/samples/jquery-photopile/src/webparts/photopileWebPart/PhotopileWebPartWebPart.ts

https://github.com/SharePoint/sp-dev-fx-webparts · TypeScript · 261 lines · 214 code · 13 blank · 34 comment · 0 complexity · 71571e39e1382178fce0912af3d7b796 MD5 · raw file

  1. import { Version } from '@microsoft/sp-core-library';
  2. import * as React from 'react';
  3. import * as ReactDom from 'react-dom';
  4. import {
  5. BaseClientSideWebPart,
  6. IPropertyPaneConfiguration,
  7. PropertyPaneTextField,
  8. IWebPartContext,
  9. PropertyPaneToggle,
  10. PropertyPaneDropdown,
  11. IPropertyPaneDropdownOption,
  12. PropertyPaneSlider
  13. } from '@microsoft/sp-webpart-base';
  14. import { escape } from '@microsoft/sp-lodash-subset';
  15. import * as strings from 'mystrings';
  16. import { IPhotopileWebPartProps } from './IPhotopileWebPartProps';
  17. import PhotopileWebPart from './components/PhotopileWebPart';
  18. import { IPhotopileWebPartWebPartProps } from './IPhotopileWebPartWebPartProps';
  19. import { SPPicturesListService } from './SPPicturesListService';
  20. import { ISPList } from './ISPList';
  21. /**
  22. * @class
  23. * Defines the Photopile client side web part
  24. */
  25. export default class PhotopileWebPartWebPart extends BaseClientSideWebPart<IPhotopileWebPartWebPartProps> {
  26. /**
  27. * @var
  28. * Stores the list of SharePoint Pictures library found in the current SP web
  29. */
  30. private listsDropdownOptions: IPropertyPaneDropdownOption[] = [];
  31. /**
  32. * @function
  33. * Web Part constructor
  34. */
  35. public constructor(context: IWebPartContext) {
  36. super();
  37. }
  38. /**
  39. * @function
  40. * Function called when the web part is inialized
  41. */
  42. public onInit<T>(): Promise<T> {
  43. //Init the PicturesListService to get the picture libs
  44. const picturesListService: SPPicturesListService = new SPPicturesListService(this.properties, this.context);
  45. //Request the libs
  46. picturesListService.getPictureLibs()
  47. .then((response) => {
  48. //Store the result as list of dropdown options
  49. this.listsDropdownOptions = response.value.map((list: ISPList) => {
  50. return {
  51. key: list.Id,
  52. text: list.Title
  53. };
  54. });
  55. });
  56. return Promise.resolve();
  57. }
  58. /**
  59. * @function
  60. * Renders the web part
  61. */
  62. public render(): void {
  63. //Constructs the react element code to JSX
  64. const element: React.ReactElement<IPhotopileWebPartProps> = React.createElement(PhotopileWebPart, {
  65. listName: this.properties.listName,
  66. orderBy: this.properties.orderBy,
  67. orderByAsc: this.properties.orderByAsc,
  68. count: this.properties.count,
  69. numLayers: this.properties.numLayers,
  70. thumbOverlap: this.properties.thumbOverlap,
  71. thumbRotation: this.properties.thumbRotation,
  72. thumbBorderWidth: this.properties.thumbBorderWidth,
  73. thumbBorderColor: this.properties.thumbBorderColor,
  74. thumbBorderHover: this.properties.thumbBorderHover,
  75. draggable: this.properties.draggable,
  76. fadeDuration: this.properties.fadeDuration,
  77. pickupDuration: this.properties.pickupDuration,
  78. photoZIndex: this.properties.photoZIndex,
  79. photoBorder: this.properties.photoBorder,
  80. photoBorderColor: this.properties.photoBorderColor,
  81. showInfo: this.properties.showInfo,
  82. autoplayGallery: this.properties.autoplayGallery,
  83. autoplaySpeed: this.properties.autoplaySpeed,
  84. context: this.context
  85. });
  86. //Render the dom
  87. ReactDom.render(element, this.domElement);
  88. }
  89. /**
  90. * @function
  91. * Prevent from changing the pane properties on typing
  92. */
  93. protected get disableReactivePropertyChanges(): boolean {
  94. return false;
  95. }
  96. /**
  97. * @function
  98. * Gets the web part properties panel settings
  99. */
  100. protected get dataVersion(): Version {
  101. return Version.parse('1.0');
  102. }
  103. protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
  104. return {
  105. pages: [
  106. {
  107. header: {
  108. description: strings.PropertyPaneDescription
  109. },
  110. //Display the web part properties as accordion
  111. displayGroupsAsAccordion: true,
  112. groups: [
  113. {
  114. groupName: strings.PictureLibraryGroupName,
  115. groupFields: [
  116. PropertyPaneDropdown('listName', {
  117. label: strings.PictureLibraryFieldLabel,
  118. options: this.listsDropdownOptions
  119. }),
  120. PropertyPaneDropdown('orderBy', {
  121. label: strings.OrderByFieldLabel,
  122. options: [
  123. { key: 'ID', text: strings.OrderByChoiceLabelId },
  124. { key: 'Title', text: strings.OrderByChoiceLabelTitle },
  125. { key: 'Created', text: strings.OrderByChoiceLabelCreated },
  126. { key: 'Modified', text: strings.OrderByChoiceLabelModified },
  127. { key: 'ImageWidth', text: strings.OrderByChoiceLabelImageWidth },
  128. { key: 'ImageHeight', text: strings.OrderByChoiceLabelImageHeight }
  129. ]
  130. }),
  131. PropertyPaneDropdown('orderByAsc', {
  132. label: strings.OrderByAscFieldLabel,
  133. options: [
  134. { key: 'asc', text: strings.OrderByAscChoiceLabel },
  135. { key: 'desc', text: strings.OrderByDescChoiceLabel }
  136. ]
  137. }),
  138. PropertyPaneSlider('count', {
  139. label: strings.PictureLibraryCountLabel,
  140. min: 1,
  141. max: 100,
  142. step: 1,
  143. showValue: true
  144. })
  145. ]
  146. },
  147. {
  148. groupName: strings.ThumbnailsGroupName,
  149. groupFields: [
  150. PropertyPaneSlider('numLayers', {
  151. label: strings.NumLayersFieldLabel,
  152. min: 1,
  153. max: 20,
  154. step: 1,
  155. showValue: true
  156. }),
  157. PropertyPaneSlider('thumbOverlap', {
  158. label: strings.ThumbOverlabFieldLabel,
  159. min: 1,
  160. max: 130,
  161. step: 1,
  162. showValue: true
  163. }),
  164. PropertyPaneSlider('thumbRotation', {
  165. label: strings.ThumbRotationFieldLabel,
  166. min: 0,
  167. max: 360,
  168. step: 1,
  169. showValue: true
  170. }),
  171. PropertyPaneSlider('thumbBorderWidth', {
  172. label: strings.ThumbBorderWidthFieldLabel,
  173. min: 0,
  174. max: 50,
  175. step: 1,
  176. showValue: true
  177. }),
  178. PropertyPaneTextField('thumbBorderColor', {
  179. label: strings.ThumbBorderColorFieldLabel
  180. }),
  181. PropertyPaneTextField('thumbBorderHover', {
  182. label: strings.ThumbBorderHoverFieldLabel
  183. }),
  184. PropertyPaneToggle('draggable', {
  185. label: strings.DraggableFieldLabel
  186. })
  187. ]
  188. },
  189. {
  190. groupName: strings.PhotoContainerGroupName,
  191. groupFields: [
  192. PropertyPaneSlider('fadeDuration', {
  193. label: strings.FadeDurationFieldLabel,
  194. min: 0,
  195. max: 5000,
  196. step: 100,
  197. showValue: true
  198. }),
  199. PropertyPaneSlider('pickupDuration', {
  200. label: strings.PickupDurationFieldLabel,
  201. min: 0,
  202. max: 5000,
  203. step: 100,
  204. showValue: true
  205. }),
  206. PropertyPaneSlider('photoZIndex', {
  207. label: strings.PhotoZIndexFieldLabel,
  208. min: 1,
  209. max: 1000,
  210. step: 1,
  211. showValue: true
  212. }),
  213. PropertyPaneSlider('photoBorder', {
  214. label: strings.PhotoBorderFieldLabel,
  215. min: 0,
  216. max: 50,
  217. step: 1,
  218. showValue: true
  219. }),
  220. PropertyPaneTextField('photoBorderColor', {
  221. label: strings.PhotoBorderColorFieldLabel
  222. }),
  223. PropertyPaneToggle('showInfo', {
  224. label: strings.ShowInfoFieldLabel
  225. })
  226. ]
  227. },
  228. {
  229. groupName: strings.AutoplayGroupName,
  230. groupFields: [
  231. PropertyPaneToggle('autoplayGallery', {
  232. label: strings.AutoplayGalleryFieldLabel
  233. }),
  234. PropertyPaneSlider('autoplaySpeed', {
  235. label: strings.AutoplaySpeedFieldLabel,
  236. min: 0,
  237. max: 5000,
  238. step: 100,
  239. showValue: true
  240. })
  241. ]
  242. }
  243. ]
  244. }
  245. ]
  246. };
  247. }
  248. }