Small adjustments on the code and improvements on the readme.

This commit is contained in:
Vesa Juvonen 2016-11-04 10:43:11 +02:00
parent e36c8c344b
commit eae60906b9
3 changed files with 75 additions and 77 deletions

View File

@ -18,4 +18,6 @@
"lib": true, "lib": true,
"temp": true "temp": true
} }
,
"typescript.check.workspaceVersion": false
} }

View File

@ -1,11 +1,13 @@
# Display List JavaScript Client-Side Web Part # Display List JavaScript Client-Side Web Part
## Summary ## Summary
Sample Web Part that demonstrates the use of JavaScript in creating a SharePoint Framework web part. The properties pane for this web part display a drop down list of lists in the current web. Once the user selects one of the lists, the web part display the contents of the list. Simplistic sample Web Part that demonstrates the use of JavaScript in creating a SharePoint Framework web part. The properties pane for this web part display a drop down list of lists in the current web. Once the user selects one of the lists, the web part display the contents of the list.
![Screeshot of the Display List web part](./assets/display-list-preview.png). ![Screeshot of the Display List web part](./assets/display-list-preview.png).
> Does only show data when hosted in SharePoint. No mock data at this point for local testing the rendering.
## Applies to ## Applies to
* [SharePoint Framework Developer Preview](http://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview) * [SharePoint Framework Developer Preview](http://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview)
@ -39,6 +41,7 @@ Version|Date|Comments
- `tsd install` - `tsd install`
- `gulp serve` - `gulp serve`
- `Open the *workbench* on your Office 365 Developer tenant` - `Open the *workbench* on your Office 365 Developer tenant`
- Basic functionality can be tested locally, data is only shown when used in context of SharePoint
## Features ## Features
The js-display-list web part displays the content of the list specified in the web part properties pane. The js-display-list web part displays the content of the list specified in the web part properties pane.

View File

@ -38,7 +38,7 @@ export default class JsDisplayListWebPart extends BaseClientSideWebPart<IJsDispl
} }
public render(): void { public render(): void {
debugger; // debugger;
this.context.statusRenderer.clearError(this.domElement); this.context.statusRenderer.clearError(this.domElement);
this.context.statusRenderer.displayLoadingIndicator(this.domElement, strings.Loading); this.context.statusRenderer.displayLoadingIndicator(this.domElement, strings.Loading);
Log.verbose('js-display-List', 'Invoking render'); Log.verbose('js-display-List', 'Invoking render');
@ -73,9 +73,9 @@ export default class JsDisplayListWebPart extends BaseClientSideWebPart<IJsDispl
}; };
} }
private _dropdownOptions: IPropertyPaneDropdownOption[] = []; private _dropdownOptions: IPropertyPaneDropdownOption[] = [];
public onInit<T>(): Promise<T> { public onInit<T>(): Promise<T> {
this._getListTitles() this._getListTitles()
.then((response) => { .then((response) => {
@ -87,7 +87,7 @@ public onInit<T>(): Promise<T> {
}); });
}); });
return Promise.resolve(); return Promise.resolve();
} }
private _getListTitles(): Promise<ISPLists> { private _getListTitles(): Promise<ISPLists> {
@ -109,43 +109,36 @@ public onInit<T>(): Promise<T> {
private _renderList(items: ISPList[]): void { private _renderList(items: ISPList[]): void {
let html: string = ''; let html: string = '';
debugger;
//debugger; //debugger;
items.forEach((item: ISPList) => { items.forEach((item: ISPList) => {
let title:string = ''; let title: string = '';
if (item.Title === null) if (item.Title === null) {
{ title = "Missing title for item with ID= " + item.Id;
title= "Missing title for item with ID= " + item.Id;
} }
else else {
{ title = item.Title;
title= item.Title;
} }
var created = item["Created"]; var created = item["Created"];
html += ` html += `
<div class="${styles.row} ms-Grid-row " }> <div class="${styles.row} ms-Grid-row " }>
<div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${title}</div> <div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${title}</div>
<div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${created.substring(0,created.length-1).replace('T',' ')}</div> <div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${created.substring(0, created.length - 1).replace('T', ' ')}</div>
<div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${item['Author'].Title}</div> <div class="ms-Grid-col ms-u-sm5 ms-u-md3 ms-u-lg4 ms-font-m">${item['Author'].Title}</div>
</div>`; </div>`;
}); });
if (items.length == 0) if (items.length == 0) {
{ html = '<br /><p class="ms-font-m-plus">The selected list is empty</p>';
html ='<br /><p class="ms-font-m-plus">The selected list is empty</p>';
} }
const listContainer: Element = this.domElement.querySelector('#spListContainer'); const listContainer: Element = this.domElement.querySelector('#spListContainer');
this.context.statusRenderer.clearLoadingIndicator(this.domElement); this.context.statusRenderer.clearLoadingIndicator(this.domElement);
listContainer.innerHTML = html; listContainer.innerHTML = html;
} }
private _renderListAsync(): void { private _renderListAsync(): void {
@ -168,7 +161,7 @@ public onInit<T>(): Promise<T> {
const listContainer: Element = this.domElement.querySelector('#spListContainer'); const listContainer: Element = this.domElement.querySelector('#spListContainer');
// Local environment // Local environment
debugger; // debugger;
if (this.context.environment.type === EnvironmentType.Local) { if (this.context.environment.type === EnvironmentType.Local) {
let html: string = '<p> Local test environment [No connection to SharePoint]</p>'; let html: string = '<p> Local test environment [No connection to SharePoint]</p>';
this.context.statusRenderer.clearLoadingIndicator(this.domElement); this.context.statusRenderer.clearLoadingIndicator(this.domElement);