added tax support

This commit is contained in:
Peter Paul Kirschner 2020-07-27 23:04:03 +02:00
parent 145180b26d
commit e02c3d111a
3 changed files with 58 additions and 51 deletions

View File

@ -1,45 +0,0 @@
{
"$schema": "https://dev.office.com/json-schemas/core-build/tslint.schema.json",
// Display errors as warnings
"displayAsWarning": true,
// The TSLint task may have been configured with several custom lint rules
// before this config file is read (for example lint rules from the tslint-microsoft-contrib
// project). If true, this flag will deactivate any of these rules.
"removeExistingRules": true,
// When true, the TSLint task is configured with some default TSLint "rules.":
"useDefaultConfigAsBase": false,
// Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules
// which are active, other than the list of rules below.
"lintConfig": {
// Opt-in to Lint rules which help to eliminate bugs in JavaScript
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-case": true,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"valid-typeof": true,
"variable-name": false,
"whitespace": false
}
}
}

View File

@ -20,6 +20,7 @@ export interface ChartConfiguration {
theme: string;
bgColors: Array<string>;
hoverColors: Array<string>;
hasTaxField?: boolean;
}
export interface IModernChartsWebPartProps {
@ -50,4 +51,4 @@ export interface MChart {
labels: Array<string>;
config: ChartConfiguration;
key: number;
}
}

View File

@ -31,6 +31,11 @@ export interface ISPList {
Id: string;
}
export interface IFieldProperty extends IPropertyPaneDropdownOption{
fieldtype: string;
}
export default class ModernChartsWebPart extends BaseClientSideWebPart<IModernChartsWebPartProps> {
private reactCharts: React.ReactElement<IModernChartsProps>;
@ -205,12 +210,30 @@ export default class ModernChartsWebPart extends BaseClientSideWebPart<IModernCh
data.forEach((item) => {
if (chLabels['unique'].indexOf(item[config.unique]) == -1 && item[config.unique] != null && item[config.unique] != "") {
chLabels['unique'].push(item[config.unique]);
chLabels['labels'].push(item[config.col1]);
//if term use VAlue
chLabels['labels'].push(this.getLabel(item,config.col1));
}
});
return chLabels;
}
private getLabel(item: Object,col:string) {
debugger;
if(item[col]!== null && item[col]['WssId']!==null && item["TaxCatchAll"].length > 0) {
//Filter because zou can have more Fields from this type to select the right value
const wssid:number = item[col]['WssId'];
const terms = (item["TaxCatchAll"]).filter((x) => x.ID === wssid );
if(terms !== null && terms.lenght >0) {
return terms[0].Term;
}
return 'TermLabel not Found';
}
//TODO HyperLink
//lookup user
return item[col];
}
private getValues(data: Array<Object>, unique: Array<string>, config: ChartConfiguration): Array<Array<any>> {
const values: Object = {};
@ -270,6 +293,21 @@ export default class ModernChartsWebPart extends BaseClientSideWebPart<IModernCh
this.properties.chartConfig[pPathInd].bgColors = newTheme['bgColors'];
this.properties.chartConfig[pPathInd].hoverColors = newTheme['hoverColors'];
}
if (pPath === 'col1' && (newValue != oldValue) )
{
this.properties.chartConfig[pPathInd].hasTaxField = false;
if( !!newValue
&& !!this.properties.chartConfig[pPathInd].columns
&& this.properties.chartConfig[pPathInd].columns.length > 0
) {
const selects=this.properties.chartConfig[pPathInd].columns.filter(f=> f.key === newValue);
if(selects.length >0) {
const selected=selects[0];
this.properties.chartConfig[pPathInd].hasTaxField = selected.fieldtype ==='TaxonomyFieldType';
}
}}
//col1
this.context.propertyPane.refresh();
this.render();
}
@ -450,14 +488,23 @@ export default class ModernChartsWebPart extends BaseClientSideWebPart<IModernCh
}
private _getListColumns(listName: string, listsite: string): Promise<any> {
return this.context.spHttpClient.get(listsite + `/_api/web/lists/GetByTitle('${listName}')/Fields?$filter=Hidden eq false and ReadOnlyField eq false and TypeAsString ne 'User' and TypeAsString ne 'Lookup'`, SPHttpClient.configurations.v1)
return this.context.spHttpClient.get(listsite + `/_api/web/lists/GetByTitle('${listName}')/Fields?$filter=Hidden eq false and ReadOnlyField eq false`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});
}
public getData(chartConfig: Object) {
return this.context.spHttpClient.get(chartConfig['dataurl'] + `/_api/web/lists/GetByTitle(\'${chartConfig['list']}\')/items?$orderby=Id desc&$limit=10&$top=${this.properties.maxResults}`, SPHttpClient.configurations.v1)
const urlparttax = '&$select=*,TaxCatchAll/Term,TaxCatchAll/ID&$expand=TaxCatchAll';
const resturl = `/_api/web/lists/GetByTitle(\'${chartConfig['list']}\')/items?$orderby=Id desc&$limit=10&$top=${this.properties.maxResults}`;
let requesturl = chartConfig['dataurl'] + resturl;
debugger;
if(!!chartConfig['hasTaxField']) {
requesturl = requesturl + urlparttax;
}
return this.context.spHttpClient.get( requesturl, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});
@ -480,10 +527,14 @@ export default class ModernChartsWebPart extends BaseClientSideWebPart<IModernCh
private _updateListColumns(siteUrl: string, listName: string, _chartConfig: ChartConfiguration): void {
this._getListColumns(listName, siteUrl).then((response) => {
var respLists: IPropertyPaneDropdownOption[] = [];
var respLists: IFieldProperty[] = [];
console.log(response.value);
for (var _key in response.value) {
respLists.push({ key: response.value[_key]['InternalName'], text: response.value[_key]['Title'] });
respLists.push({
key: response.value[_key]['InternalName'],
text: response.value[_key]['Title'] ,
fieldtype: response.value[_key]['TypeAsString']
});
}
this._columnOptions = respLists;
_chartConfig.columns = respLists;