Merge pull request #1312 from nanddeepn/master

Fixed external CDN reference issue with js-modern-calendar
This commit is contained in:
Hugo Bernier 2020-06-07 13:06:42 -04:00 committed by GitHub
commit bcdaaee967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 183 additions and 176 deletions

View File

@ -1,14 +1,18 @@
{
"entries": [
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"modern-calendar.bundle": {
"components": [
{
"entry": "./lib/webparts/modernCalendar/ModernCalendarWebPart.js",
"manifest": "./src/webparts/modernCalendar/ModernCalendarWebPart.manifest.json",
"outputPath": "./dist/modern-calendar.bundle.js"
"entrypoint": "./lib/webparts/modernCalendar/ModernCalendarWebPart.js",
"manifest": "./src/webparts/modernCalendar/ModernCalendarWebPart.manifest.json"
}
]
}
],
"externals": {
},
"localizedResources": {
"modernCalendarStrings": "webparts/modernCalendar/loc/{locale}.js"
}
"modernCalendarStrings": "lib/webparts/modernCalendar/loc/{locale}.js"
},
"externals": {}
}

View File

@ -1,8 +1,9 @@
{
"solution": {
"name": "spFX Modern Calendar",
"name": "SPFx Modern Calendar",
"id": "3d593a2f-73f1-486f-9dae-555c6f6b584d",
"version": "1.0.0.1"
"version": "1.0.0.1",
"includeClientSideAssets": true
},
"paths": {
"zippedPackage": "solution/modern-calendar.sppkg"

View File

@ -1,3 +1,4 @@
{
"cdnBasePath": "https://publiccdn.sharepointonline.com/pcpro365.sharepoint.com/163800463de5f9285ad4f6f9cc0a97985b96b057e062d4733849cc0fc90eeffbd6d72bb8/calendar/"
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -34,7 +34,7 @@ export default class CalendarTemplate {
`;
}
public static themeBase: string = `https://publiccdn.sharepointonline.com/pcpro365.sharepoint.com/163800463de5f9285ad4f6f9cc0a97985b96b057e062d4733849cc0fc90eeffbd6d72bb8/calendar/themes/`;
public static themeBase: string = `https://code.jquery.com/ui/1.12.1/themes/`;
public static themeNames: Array<string> = [
'default',
@ -63,12 +63,12 @@ export default class CalendarTemplate {
'ui-darkness',
'ui-lightness',
'vader'
]
];
public static theme(): IPropertyPaneDropdownOption[] {
var themes: IPropertyPaneDropdownOption[] = [];
CalendarTemplate.themeNames.forEach(function(name,index) {
themes.push({key: CalendarTemplate.themeBase + name + '/jquery-ui.min.css', text: name.toLocaleUpperCase()})
themes.push({key: CalendarTemplate.themeBase + name + '/jquery-ui.min.css', text: name.toLocaleUpperCase()});
});
return themes;
}

View File

@ -39,27 +39,27 @@ export interface ISPList {
}
export interface EventObjects {
value: EventObjectInput [];
value: EventObjectInput[];
}
export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModernCalendarWebPartProps> {
public constructor() {
super();
//Modify with your a CDN or local path
SPComponentLoader.loadCss('//publiccdn.sharepointonline.com/pcpro365.sharepoint.com/163800463de5f9285ad4f6f9cc0a97985b96b057e062d4733849cc0fc90eeffbd6d72bb8/calendar/sweetalert2.min.css');
SPComponentLoader.loadCss('//publiccdn.sharepointonline.com/pcpro365.sharepoint.com/163800463de5f9285ad4f6f9cc0a97985b96b057e062d4733849cc0fc90eeffbd6d72bb8/calendar/fullcalendar.min.css');
// Modify with your a CDN or local path
SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.css');
SPComponentLoader.loadCss('https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.9.0/fullcalendar.min.css');
}
public render(): void {
if (this.properties.theme != null){
if (this.properties.theme != null) {
SPComponentLoader.loadCss(this.properties.theme);
}
if (!this.properties.other){
if (!this.properties.other) {
jQuery('input[aria-label=hide-col]').parent().hide();
}
//Check required properties before rendering list
if (this.properties.listTitle == null || this.properties.start == null || this.properties.end == null || this.properties.title == null || this.properties.detail == null) {
this.domElement.innerHTML = CalendarTemplate.emptyHtml(this.properties.description);
@ -75,37 +75,38 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
protected onPropertyPaneConfigurationStart(): void {
//Set a default theme
if (this.properties.theme == null){
if (this.properties.theme == null) {
this.properties.theme = CalendarTemplate.theme()[0].key.toString();
}
if (this.properties.site){
if (this.properties.site) {
this.listDisabled = false;
}
if (this.properties.listTitle && (!this.properties.start || !this.properties.end || !this.properties.title || !this.properties.detail)){
if (this.properties.listTitle && (!this.properties.start || !this.properties.end || !this.properties.title || !this.properties.detail)) {
//this._getColumnsAsync();
}
if (!this.properties.other){
if (!this.properties.other) {
jQuery('input[aria-label=hide-col]').parent().hide();
}
if (this.properties.site && this.properties.listTitle && this.properties.start && this.properties.start && this.properties.end && this.properties.title && this.properties.detail){
if (this.properties.site && this.properties.listTitle && this.properties.start && this.properties.start && this.properties.end && this.properties.title && this.properties.detail) {
this.context.statusRenderer.displayLoadingIndicator(this.domElement, 'Configuration');
this._getSiteRootWeb()
.then((response0) => {
this._getSites(response0['Url'])
.then((response) => {
var sites: IPropertyPaneDropdownOption[] = [];
sites.push({key:this.context.pageContext.web.absoluteUrl, text:'This Site'});
sites.push({key:'other', text:'Other Site (Specify Url)'});
sites.push({ key: this.context.pageContext.web.absoluteUrl, text: 'This Site' });
sites.push({ key: 'other', text: 'Other Site (Specify Url)' });
for (var _key in response.value) {
if (this.context.pageContext.web.absoluteUrl != response.value[_key]['Url']){
sites.push({key: response.value[_key]['Url'], text: response.value[_key]['Title']});
if (this.context.pageContext.web.absoluteUrl != response.value[_key]['Url']) {
sites.push({ key: response.value[_key]['Url'], text: response.value[_key]['Title'] });
}
}
this._siteOptions = sites;
if (this.properties.site ){
if (this.properties.site) {
this._getListTitles(this.properties.site)
.then((response2) => {
this._dropdownOptions = response2.value.map((list: ISPList) => {
@ -114,11 +115,11 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
text: list.Title
};
});
this._getListColumns(this.properties.listTitle,this.properties.site)
this._getListColumns(this.properties.listTitle, this.properties.site)
.then((response3) => {
var col: IPropertyPaneDropdownOption[] = [];
for (var _key in response3.value) {
col.push({key: response3.value[_key]['InternalName'], text: response3.value[_key]['Title']});
col.push({ key: response3.value[_key]['InternalName'], text: response3.value[_key]['Title'] });
}
this._columnOptions = col;
this.colsDisabled = false;
@ -137,7 +138,7 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
}
protected onPropertyPaneFieldChanged(propertyPath: string, oldValue: any, newValue: any): void {
if (newValue == 'other' ){
if (newValue == 'other') {
this.properties.other = true;
this.properties.listTitle = null;
jQuery('input[aria-label=hide-col]').parent().show();
@ -153,7 +154,7 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
this.listDisabled = true;
var siteUrl = newValue;
if (this.properties.other) { siteUrl = this.properties.siteOther; } else { jQuery('input[aria-label=hide-col]').parent().hide(); }
if ((this.properties.other && this.properties.siteOther.length > 25) || !this.properties.other){
if ((this.properties.other && this.properties.siteOther.length > 25) || !this.properties.other) {
this._getListTitles(siteUrl)
.then((response) => {
this._dropdownOptions = response.value.map((list: ISPList) => {
@ -172,11 +173,11 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
// tslint:disable-next-line:no-duplicate-variable
var siteUrl = newValue;
if (this.properties.other) { siteUrl = this.properties.siteOther; }
this._getListColumns(newValue,siteUrl)
this._getListColumns(newValue, siteUrl)
.then((response) => {
var col: IPropertyPaneDropdownOption[] = [];
for (var _key in response.value) {
col.push({key: response.value[_key]['InternalName'], text: response.value[_key]['Title']});
col.push({ key: response.value[_key]['InternalName'], text: response.value[_key]['Title'] });
}
this._columnOptions = col;
this.colsDisabled = false;
@ -284,7 +285,7 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
});
}
private _getListColumns(listNameColumns: string,listsite: string): Promise<any> {
private _getListColumns(listNameColumns: string, listsite: string): Promise<any> {
return this.context.spHttpClient.get(listsite + `/_api/web/lists/GetByTitle('${listNameColumns}')/Fields?$filter=Hidden eq false and ReadOnlyField eq false`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
@ -292,14 +293,14 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
}
private _getListData(listName: string, site: string): Promise<any> {
return this.context.spHttpClient.get(site + `/_api/web/lists/GetByTitle('${listName}')/items?$select=${encodeURIComponent(this.properties.title)},${encodeURIComponent(this.properties.start)},${encodeURIComponent(this.properties.end)},${encodeURIComponent(this.properties.detail)},Created,Author/ID,Author/Title&$expand=Author/ID,Author/Title&$orderby=Id desc&$limit=500`,SPHttpClient.configurations.v1)
return this.context.spHttpClient.get(site + `/_api/web/lists/GetByTitle('${listName}')/items?$select=${encodeURIComponent(this.properties.title)},${encodeURIComponent(this.properties.start)},${encodeURIComponent(this.properties.end)},${encodeURIComponent(this.properties.detail)},Created,Author/ID,Author/Title&$expand=Author/ID,Author/Title&$orderby=Id desc&$limit=500`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});
}
private _renderList(items: any[]): void {
var calItems: EventObjectInput [] = items.map((list: any) => {
var calItems: EventObjectInput[] = items.map((list: any) => {
return {
title: list[this.properties.title],
start: list[this.properties.start],
@ -309,13 +310,13 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
};
});
this.context.statusRenderer.clearLoadingIndicator(this.domElement);
const calendarOptions:EventObjectInput = {
const calendarOptions: EventObjectInput = {
title: "test",
theme: true,
events: calItems,
eventClick: (_event) => {
var eventDetail = moment(_event['start']).format('MM/DD/YYYY hh:mm') + ' - ' + moment(_event['end']).format('MM/DD/YYYY hh:mm') + '<br>' + _event['detail'];
swal2.default(_event.title,eventDetail,'info');
swal2.default(_event.title, eventDetail, 'info');
}
};
jQuery('.spfxcalendar', this.domElement).fullCalendar(calendarOptions);
@ -327,10 +328,10 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
this._getSites(response['Url'])
.then((response1) => {
var sites: IPropertyPaneDropdownOption[] = [];
sites.push({key:this.context.pageContext.web.absoluteUrl, text:'This Site'});
sites.push({key:'other', text:'Other Site (Specify Url)'});
sites.push({ key: this.context.pageContext.web.absoluteUrl, text: 'This Site' });
sites.push({ key: 'other', text: 'Other Site (Specify Url)' });
for (var _key in response1.value) {
sites.push({key: response1.value[_key]['Url'], text: response1.value[_key]['Title']});
sites.push({ key: response1.value[_key]['Url'], text: response1.value[_key]['Title'] });
}
this._siteOptions = sites;
this.context.propertyPane.refresh();
@ -346,11 +347,11 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
});
this.context.propertyPane.refresh();
if (this.properties.listTitle) {
this._getListColumns(this.properties.listTitle,this.properties.site)
this._getListColumns(this.properties.listTitle, this.properties.site)
.then((response3) => {
var col: IPropertyPaneDropdownOption[] = [];
for (var _key in response3.value) {
col.push({key: response3.value[_key]['InternalName'], text: response3.value[_key]['Title']});
col.push({ key: response3.value[_key]['InternalName'], text: response3.value[_key]['Title'] });
}
this._columnOptions = col;
this.colsDisabled = false;
@ -373,7 +374,7 @@ export default class ModernCalendarWebPart extends BaseClientSideWebPart<IModern
this._renderList(response.value);
}).catch((err) => {
this.context.statusRenderer.clearLoadingIndicator(this.domElement);
this.context.statusRenderer.renderError(this.domElement,"There was an error loading your list, please verify the selected list has Calendar Events or choose a new list.");
this.context.statusRenderer.renderError(this.domElement, "There was an error loading your list, please verify the selected list has Calendar Events or choose a new list.");
});
}