<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SharePointFramework &#8211; 株式会社カジトリ 技術ブログ</title>
	<atom:link href="https://develop.kajitori.co.jp/archives/tag/sharepointframework/feed" rel="self" type="application/rss+xml" />
	<link>https://develop.kajitori.co.jp</link>
	<description>Officeアドイン、Laravel、Exmentなどの技術記事を記載します。</description>
	<lastBuildDate>Tue, 26 Jan 2021 14:14:11 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://develop.kajitori.co.jp/wp-content/uploads/2021/01/cropped-logo1-32x32.png</url>
	<title>SharePointFramework &#8211; 株式会社カジトリ 技術ブログ</title>
	<link>https://develop.kajitori.co.jp</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Sharepoint Frameworkにプロパティ要素を追加し、画面から設定値を変更できるようにする</title>
		<link>https://develop.kajitori.co.jp/archives/61</link>
					<comments>https://develop.kajitori.co.jp/archives/61#respond</comments>
		
		<dc:creator><![CDATA[hsatou]]></dc:creator>
		<pubDate>Mon, 17 Jun 2019 12:14:27 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePointFramework]]></category>
		<category><![CDATA[TypeScrript]]></category>
		<guid isPermaLink="false">https://develop.kajitori.co.jp/?p=61</guid>

					<description><![CDATA[はじめに 前回の記事では、SharePoint Framework内でWordPress REST API処理を追加し、SharePointページ内でコンテンツを表示する対応を行いました。 しかし前回の記事のままだと、取...]]></description>
										<content:encoded><![CDATA[<h1>はじめに</h1>
<p>前回の記事では、SharePoint Framework内でWordPress REST API処理を追加し、SharePointページ内でコンテンツを表示する対応を行いました。</p>
<p>しかし前回の記事のままだと、取得先のWordPressのURLは、ソースコード内に埋め込まれており、変更できません。<br />
URLを変更するためには、都度ソースコードを変更する必要があり、非常に面倒です。</p>
<p>そのため今回は、SharePoint Frameworkにプロパティ要素を追加し、画面から設定値を変更できるようにする機能を追加します。<br />
今回は、「取得先のWordPressのURLを、画面から変更できるようにする対応」とします。</p>
<p><!-- more --></p>
<h2>SharePoint Frameworkのプロパティとは</h2>
<p>前回作成したWebパーツを起動すると、「Edit web part」と、Webパーツを編集するタイルが表示されています。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190617140038-300x183.png" alt="" /></p>
<p>このボタンをクリックすると、画面右に、プロパティを変更する要素が表示されます。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190617140211-276x300.png" alt="" /></p>
<p>現在は「Description Field」、つまり説明文を変更する要素のみになりますが、今回はここに、取得先のWordPress APIを変更できるようにしていきます。</p>
<h1>実装</h1>
<p>今回の参考資料：<br />
<a href="https://docs.microsoft.com/ja-jp/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part#configure-the-web-part-property-pane">https://docs.microsoft.com/ja-jp/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part#configure-the-web-part-property-pane</a></p>
<h2>プロパティの追加</h2>
<ul>
<li>前回修正した、「SharePointWordpressWebPart.ts」（アプリ名.ts）ファイルを開き、先頭の以下の要素を確認します。</li>
</ul>
<pre><code class="language-typescript">import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField
} from &#039;@microsoft/sp-property-pane&#039;;</code></pre>
<p>この「PropertyPaneTextField」というのが、プロパティのテキストフィールドになります。<br />
ここで、プロパティ要素にチェックボックスを追加したい場合はPropertyPaneCheckbox、ドロップダウンメニューの場合はPropertyPaneDropdownなどを追加してください。<br />
例：  </p>
<pre><code class="language-typescript">import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField,
  PropertyPaneCheckbox,
  PropertyPaneDropdown
} from &#039;@microsoft/sp-property-pane&#039;;</code></pre>
<p>※今回については、種類はテキストフィールドのみなので、上記の追加は不要です</p>
<ul>
<li>同じtsファイル内のインタフェース、「ISharePointWordpressWebPartProps」を確認します。デフォルトだと以下のようになっております。</li>
</ul>
<pre><code class="language-typescript">export interface ISharePointWordpressWebPartProps {
  description: string;
}</code></pre>
<p>ここに、プロパティとして追加したい要素と、その種類を追記していきます。<br />
今回はWordPressのURLなので、以下のように追加してください。その後、ファイルを保存します。</p>
<pre><code class="language-typescript">export interface ISharePointWordpressWebPartProps {
  description: string;
  wordPressUrl: string;
}</code></pre>
<ul>
<li>その下の、getPropertyPaneConfigurationメソッドを確認します。<br />
デフォルトだと、以下のような記述になっております。</li>
</ul>
<pre><code class="language-typescript">protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField(&#039;description&#039;, {
                  label: strings.DescriptionFieldLabel
                })
              ]
            }
          ]
        }
      ]
    };
  }</code></pre>
<p>これを修正し、wordPressUrl要素を追加していきます。<br />
具体的には、以下のようになります。  </p>
<pre><code class="language-typescript">protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField(&#039;description&#039;, {
                  label: strings.DescriptionFieldLabel
                }),
                // 追加-開始
                PropertyPaneTextField(&#039;wordPressUrl&#039;, {
                  label: &#039;WordPress URL&#039;
                }),
                // 追加-終了
              ]
            }
          ]
        }
      ]
    };
  }</code></pre>
<p>これで、SharePointWordpressWebPart.tsに関する設定は完了です。  </p>
<h2>デフォルト値の修正</h2>
<p>アプリのプロパティ既定値を追加していきます。  </p>
<ul>
<li>「SharePointWordpressWebPart.manifest.json」(アプリ名.manifest.json)を開きます。<br />
標準だと以下のような記載がされています。</li>
</ul>
<pre><code class="language-json">  &quot;preconfiguredEntries&quot;: [{
    &quot;groupId&quot;: &quot;5c03119e-3074-46fd-976b-c60198311f70&quot;, // Other
    &quot;group&quot;: { &quot;default&quot;: &quot;Other&quot; },
    &quot;title&quot;: { &quot;default&quot;: &quot;SharePointWordpress&quot; },
    &quot;description&quot;: { &quot;default&quot;: &quot;SharePointWordpress description&quot; },
    &quot;officeFabricIconFontName&quot;: &quot;Page&quot;,
    &quot;properties&quot;: {
      &quot;description&quot;: &quot;SharePointWordpress&quot;
    }
  }]
}</code></pre>
<ul>
<li>preconfiguredEntries &gt; properties が、プロパティの既定に関する内容です。<br />
この内容を変更します。今回は前回同等、弊社で提供しているサービスのURLにします。<br />
（他社のブログにアクセスするのも問題なので）</li>
</ul>
<pre><code class="language-json">  &quot;preconfiguredEntries&quot;: [{
    &quot;groupId&quot;: &quot;5c03119e-3074-46fd-976b-c60198311f70&quot;, // Other
    &quot;group&quot;: { &quot;default&quot;: &quot;Other&quot; },
    &quot;title&quot;: { &quot;default&quot;: &quot;SharePointWordpress&quot; },
    &quot;description&quot;: { &quot;default&quot;: &quot;SharePointWordpress description&quot; },
    &quot;officeFabricIconFontName&quot;: &quot;Page&quot;,
    &quot;properties&quot;: {
      &quot;description&quot;: &quot;SharePointWordpress&quot;,
      &quot;wordPressUrl&quot;: &quot;https://exment.net&quot;
    }
  }]
}</code></pre>
<ul>
<li>Ctrl + Shift + Bでビルドを行い、以下のコマンドでWorkBenchを表示します。  </li>
</ul>
<pre><code>gulp serve</code></pre>
<p>これで、先ほど確認したプロパティを表示すると、「WordPress URL」入力テキスト欄が追加されています。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190617143854-300x256.png" alt="" /></p>
<h2>プロパティ値をWebパーツに埋め込む</h2>
<p>いよいよ、今回作成したプロパティwordPressUrlを、Webパーツに埋め込む処理を追加していきます。  </p>
<ul>
<li>WordPress.tsのgetWordpressHtmlを、引数よりWordPressのURLを取得する方式に修正します。  </li>
</ul>
<pre><code class="language-typescript">export default class WordPress {
  public static getWordpressHtml = (wordPressUrl) =&gt; {
    var $defer = $.Deferred();
    var apiUrl = wordPressUrl + &#039;/wp-json/wp/v2/posts?_embed&#039;;
    $.getJSON(apiUrl).then((data) =&gt; {
        // 以下省略</code></pre>
<p>apiUrlを、wordPressUrl + '/wp-json/wp/v2/posts?_embed' より作成する方式に修正しました。  </p>
<ul>
<li>SharePointWordpressWebPart.tsのrender関数を修正します。  </li>
</ul>
<pre><code class="language-typescript">public render(): void {
    var wordPressUrl = this.properties.wordPressUrl;  // ポイント
    WordPress.getWordpressHtml(wordPressUrl)
      .then((html:string) =&gt; {
        $(this.domElement).html(html); 
      });
  }</code></pre>
<p>ポイントは「this.properties.wordPressUrl」です。<span style="font-weight:bold; color:red">this.propertiesで、プロパティ値を取得できます。</span><br />
今回はthis.properties.wordPressUrlで、WordPressのURLを取得しています。  </p>
<p>これにより、WordPressのURLを、画面から取得するようになりました。<br />
試しに、URLを変更してみます。プロパティウィンドウを開き、WordPress URLを、かつて私が書いていた個人ブログに変更します。  </p>
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190617145009-300x152.png" alt="" />
<p><small>めちゃくちゃ色々語ってますねｗ</small><br />
このように、画面からURLを変更することで、取得先のURLを変更することができます。  </p>
<p>ちなみに、レンダリング時に直接埋め込むことも可能なようです。<br />
参考サイトだと、以下のように記載しておりました。この中の「this.properties.description」が該当します。  </p>
<pre><code class="language-typescript">public render(): void {
  this.domElement.innerHTML = `
    &lt;div class=&quot;${ styles.helloWorld }&quot;&gt;
      &lt;div class=&quot;${ styles.container }&quot;&gt;
        &lt;div class=&quot;${ styles.row }&quot;&gt;
          &lt;div class=&quot;${ styles.column }&quot;&gt;
            &lt;span class=&quot;${ styles.title }&quot;&gt;Welcome to SharePoint!&lt;/span&gt;
            &lt;p class=&quot;${ styles.subTitle }&quot;&gt;Customize SharePoint experiences using web parts.&lt;/p&gt;
            &lt;p class=&quot;${ styles.description }&quot;&gt;${escape(this.properties.description)}&lt;/p&gt;
            &lt;a href=&quot;https://aka.ms/spfx&quot; class=&quot;${ styles.button }&quot;&gt;
              &lt;span class=&quot;${ styles.label }&quot;&gt;Learn more&lt;/span&gt;
            &lt;/a&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;`;
}</code></pre>
<h1>まとめ</h1>
<p>このように、プロパティを設定することで、ユーザーによる柔軟な設定変更ができるようになります。<br />
設定値は可能な限りプロパティ値にすることで、変化に柔軟なアプリ作りを心掛けましょう！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://develop.kajitori.co.jp/archives/61/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SharepointFrameworkを試してみる[WordPressの記事を表示]</title>
		<link>https://develop.kajitori.co.jp/archives/56</link>
					<comments>https://develop.kajitori.co.jp/archives/56#respond</comments>
		
		<dc:creator><![CDATA[hsatou]]></dc:creator>
		<pubDate>Mon, 17 Jun 2019 12:09:13 +0000</pubDate>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePointFramework]]></category>
		<guid isPermaLink="false">https://develop.kajitori.co.jp/?p=56</guid>

					<description><![CDATA[はじめに SharepointFrameworkの検証を行います。 この記事では、以下について扱います。 SharePointFrameworkのインストール とりあえずSharePointFrameworkで実行してみ...]]></description>
										<content:encoded><![CDATA[<h1>はじめに</h1>
<p>SharepointFrameworkの検証を行います。<br />
この記事では、以下について扱います。  </p>
<ol>
<li>SharePointFrameworkのインストール</li>
<li>とりあえずSharePointFrameworkで実行してみる</li>
<li>jqueryの追加</li>
<li>独自処理 - WordPress連携部分の追加</li>
</ol>
<p>※SharepointFrameworkの概念の話はしません。それはまた別の機会に。</p>
<h1>実装</h1>
<h2>今回の参考資料</h2>
<p><a href="https://docs.microsoft.com/ja-jp/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part">https://docs.microsoft.com/ja-jp/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part</a></p>
<p><!-- more --></p>
<h2>SharePointFrameworkのインストール</h2>
<ul>
<li>nodeを未インストールの場合、nodeをインストール   </li>
</ul>
<p><a href="https://nodejs.org/ja/">https://nodejs.org/ja/</a></p>
<ul>
<li>
<p>npm確認</p>
<pre><code>npm --version</code></pre>
</li>
<li>
<p>必要パッケージインストール</p>
<pre><code>npm install -g yo gulp
npm install -g @microsoft/generator-sharepoint</code></pre>
</li>
<li>
<p>SharepointFrameworkインストール先のフォルダを作成</p>
</li>
</ul>
<pre><code>mkdir SharePointWordpress
cd SharePointWordpress</code></pre>
<ul>
<li>SharepointFrameworkインストール実行
<pre><code>yo @microsoft/sharepoint</code></pre>
</li>
</ul>
<p>ここで、対話式でさまざまなことを聞かれるので、回答します。  </p>
<pre><code>  What is your solution name? : (任意のソリューション名)  
  Which baseline packages do you want to target for your component(s)? :(そのままEnter。SharePoint Onlineのみ)  
  Where do you want to place the files? : (そのままEnter。カレントフォルダにインストール)  
  Do you want to allow the tenant admin the choice of being able to deploy the solution to all sites immediately without running any feature deployment or adding apps in sites? : (N)  
  Will the components in the solution require permissions to access web APIs that are unique and not shared with other components in the tenant? : (N)  
  Which type of client-side component to create? : (そのままEnter。WebPart)  
  What is your Web part name? : (任意のWebパーツ名。この名前が画面に表示される様子)
  What is your Web part description? : (説明文。面倒なのでそのままEnter)
  Which framework would you like to use? : (JSのフレームワーク。Reactとか使う場合は指定する様子)  </code></pre>
<p>これが完了したら、インストールが開始されます。超時間かかりますが、待ちましょう。</p>
<ul>
<li>
<p>Visual Studio Codeで、インストールしたフォルダを開いて起動</p>
</li>
<li>
<p>Ctrl + Shift + Bで、gulpのビルド実行<br />
gulp buildを選択 → タスクのスキャンを出力せず実行 をクリック<br />
→これで、元々入っているSharePointFrameworkのビルドが実行されます。  </p>
</li>
<li>
<p>VSCodeで、以下のコマンドを実行</p>
<pre><code>gulp serve</code></pre>
<p>→ブラウザが立ち上がり、SharePoint WorkBenchが起動します。</p>
</li>
<li>
<p>「+」ボタンをクリック後、パーツ名をクリックし、Webパーツを配置します。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190605210417-300x140.png" alt="" /></p>
</li>
<li>
<p>既定のパーツが配置されていることを確認します。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190605210505-300x103.png" alt="" /></p>
</li>
</ul>
<h2>カスタマイズ</h2>
<p>デフォルト設定で起動できることを確認したら、ここからカスタマイズをしていきましょう。  </p>
<h3>jquery追加</h3>
<p>まずはjqueryの追加です。</p>
<ul>
<li>
<p>VSCodeで、以下のコマンドを実行</p>
<pre><code>npm install jquery@2 --save
npm install @types/jquery@2 --save</code></pre>
</li>
<li>
<p>VSCodeで、config/config.jsonを開き、externalsに以下を追加</p>
<pre><code class="language-json">&quot;jquery&quot;:&quot;node_modules/jquery/dist/jquery.min.js&quot;</code></pre>
</li>
</ul>
<h3>独自処理を追加</h3>
<p>独自処理として、今回はWordPressのAPIを使用し、WordPressの記事一覧を取得し表示します。<br />
※WordPressの向き先は、とりあえず自社サービスのものにしています。</p>
<ul>
<li>src\webparts\sharePointWordpressに、WordPress.tsを追加します。<br />
その後、以下のコードを追加します。</li>
</ul>
<pre><code class="language-typescript">import * as $ from &#039;jquery&#039;;

export default class WordPress {
  public static getWordpressHtml = () =&gt; {
    var $defer = $.Deferred();

    // wordpressのAPIのURL
    $.getJSON(&#039;https://exment.net/wp-json/wp/v2/posts?_embed&#039;).then((data) =&gt; {
          console.log(data);

          var html = &#039;&#039;;
          for(var index in data){
              var d = data[index];

              var title = d.title.rendered;
              var link = d.link;
              var excerpt = d.excerpt.rendered;
              var date = d.date;

              // ul作成
              var $a = $(&#039;&lt;a/&gt;&#039;, {&#039;href&#039; : link, &#039;style&#039; : &#039;margin-bottom:4em; display:block;&#039;});
              var $ul = $(&#039;&lt;ul/&gt;&#039;);

              $ul.append($(&#039;&lt;li/&gt;&#039;, {&#039;text&#039;: &#039;タイトル：&#039; + title}));
              $ul.append($(&#039;&lt;li/&gt;&#039;, {&#039;text&#039;: &#039;日付：&#039; + date}));
              $ul.append($(&#039;&lt;li/&gt;&#039;, {&#039;html&#039;: &#039;本文：&#039; + excerpt}));

              $a.append($ul);

              html += $a[0].outerHTML;
          }

          $defer.resolve(html);
      });

    return $defer.promise();
  }

}
</code></pre>
<ul>
<li>src\webparts\sharePointWordpress\SharePointWordpressWebPart.tsの記述を修正します。</li>
</ul>
<pre><code class="language-typescript">import { Version } from &#039;@microsoft/sp-core-library&#039;;
import { BaseClientSideWebPart } from &#039;@microsoft/sp-webpart-base&#039;;
import {
  IPropertyPaneConfiguration,
  PropertyPaneTextField
} from &#039;@microsoft/sp-property-pane&#039;;
import { escape } from &#039;@microsoft/sp-lodash-subset&#039;;

import styles from &#039;./SharePointWordpressWebPart.module.scss&#039;;
import * as strings from &#039;SharePointWordpressWebPartStrings&#039;;

///// 追加---s
import * as $ from &#039;jquery&#039;;
//WordPress.tsを読み込む
import WordPress from &#039;./WordPress&#039;;
///// 追加---e

export interface ISharePointWordpressWebPartProps {
  description: string;
}

export default class SharePointWordpressWebPart extends BaseClientSideWebPart&lt;ISharePointWordpressWebPartProps&gt; {

  public render(): void {
    ///// 修正---s
    // WordPress.ts内のgetWordpressHtml実行
    WordPress.getWordpressHtml()
      .then((html:string) =&gt; {
        $(this.domElement).html(html); 
      });
    ///// 修正---e
  }

  protected get dataVersion(): Version {
    return Version.parse(&#039;1.0&#039;);
  }

  protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
    return {
      pages: [
        {
          header: {
            description: strings.PropertyPaneDescription
          },
          groups: [
            {
              groupName: strings.BasicGroupName,
              groupFields: [
                PropertyPaneTextField(&#039;description&#039;, {
                  label: strings.DescriptionFieldLabel
                })
              ]
            }
          ]
        }
      ]
    };
  }
}
</code></pre>
<ul>
<li>
<p>再度Ctrl + Shift + Bで、ビルドを行います。<br />
その後Sharepoint WorkBenchにアクセスすることで、WordPressの記事一覧が表示されます。<br />
<img decoding="async" src="https://develop.kajitori.co.jp/wp-content/uploads/2021/01/20190605205537-300x150.png" alt="" /></p>
</li>
<li>
<p>無事、jqueryも呼び出した上で、独自の実装を実現できました！</p>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://develop.kajitori.co.jp/archives/56/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
