react-tenant-properties (#806)
* commit * Tree Organization Chart * React-Birthdays - Convert birthdate from UTC to local * commit react-tenant-properties commit react-tenant-properties * update project name * Update README.md Change docs * Update README.md
This commit is contained in:
parent
8609ea0544
commit
ebb56d3da5
|
@ -0,0 +1,25 @@
|
||||||
|
# EditorConfig helps developers define and maintain consistent
|
||||||
|
# coding styles between different editors and IDEs
|
||||||
|
# editorconfig.org
|
||||||
|
|
||||||
|
root = true
|
||||||
|
|
||||||
|
|
||||||
|
[*]
|
||||||
|
|
||||||
|
# change these settings to your own preference
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
# we recommend you to keep these unchanged
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[{package,bower}.json]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"@pnp/generator-spfx": {
|
||||||
|
"framework": "react",
|
||||||
|
"pnpFramework": "reactjs.plus",
|
||||||
|
"pnp-libraries": [
|
||||||
|
"jquery@3",
|
||||||
|
"@pnp/pnpjs",
|
||||||
|
"@pnp/spfx-property-controls",
|
||||||
|
"@pnp/spfx-controls-react"
|
||||||
|
],
|
||||||
|
"pnp-ci": [],
|
||||||
|
"pnp-vetting": [],
|
||||||
|
"spfxenv": "spo"
|
||||||
|
},
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"environment": "spo",
|
||||||
|
"framework": "react",
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"version": "1.7.1",
|
||||||
|
"libraryName": "react-tenant-properties",
|
||||||
|
"libraryId": "d5bc38a6-0b5c-4644-9087-efa6de87ece1",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
# React Tenant Properties Web Part
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
This web part allows tenant administrators to manage tenant properties through a graphical interface.
|
||||||
|
We can create, edit or delete tenant properties.
|
||||||
|
|
||||||
|
Only users with Tenant Admin Role are allowed to managed tenant properties.
|
||||||
|
#### User without Tenant Admin Role got this message
|
||||||
|
![tenant properties](https://github.com/joaojmendes/sp-dev-fx-webparts/blob/master/samples/react-tenant-properties/assets/TenantProperties5.jpg)
|
||||||
|
#### List tenant properties
|
||||||
|
![tenant properties](https://github.com/joaojmendes/sp-dev-fx-webparts/blob/master/samples/react-tenant-properties/assets/TenantProperties1.jpg)
|
||||||
|
|
||||||
|
#### Add Tenant property
|
||||||
|
![tenant properties](https://github.com/joaojmendes/sp-dev-fx-webparts/blob/master/samples/react-tenant-properties/assets/TenantProperties2.jpg)
|
||||||
|
|
||||||
|
#### Edit tenant property
|
||||||
|
![tenant properties](https://github.com/joaojmendes/sp-dev-fx-webparts/blob/master/samples/react-tenant-properties/assets/TenantProperties3.jpg)
|
||||||
|
|
||||||
|
#### Delete tenant property
|
||||||
|
![tenant properties](https://github.com/joaojmendes/sp-dev-fx-webparts/blob/master/samples/react-tenant-properties/assets/TenantProperties4.jpg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Used SharePoint Framework Version
|
||||||
|
![drop](https://img.shields.io/badge/version-GA-green.svg)
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
* [SharePoint Framework](https:/dev.office.com/sharepoint)
|
||||||
|
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
|
||||||
|
|
||||||
|
> Update accordingly as needed.
|
||||||
|
|
||||||
|
## WebPart Properties
|
||||||
|
|
||||||
|
Property |Type|Required| comments
|
||||||
|
--------------------|----|--------|----------
|
||||||
|
WebPart Title| Text| no|
|
||||||
|
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
The Web Part Use MSGraph API and need to SharePoint Administrator appprove de scope "Directory.ReadWrite.All" in SharePoint Admin Center.
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
Tenant Properties WebPart|João Mendes
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
1.0.0|Mar 08, 2019|Initial release
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Minimal Path to Awesome
|
||||||
|
|
||||||
|
- Clone this repository
|
||||||
|
- in the command line run:
|
||||||
|
- `npm install`
|
||||||
|
- `gulp build`
|
||||||
|
- `gulp bundle --ship`
|
||||||
|
- `gulp package-solution --ship`
|
||||||
|
- `Add to AppCatalog and deploy`
|
||||||
|
- `Approve API permission on SharePoint Admin Center`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/readme-template" />
|
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
Binary file not shown.
After Width: | Height: | Size: 83 KiB |
Binary file not shown.
After Width: | Height: | Size: 86 KiB |
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"tenant-properties-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/tenantProperties/TenantPropertiesWebPart.js",
|
||||||
|
"manifest": "./src/webparts/tenantProperties/TenantPropertiesWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"TenantPropertiesWebPartStrings": "lib/webparts/tenantProperties/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js",
|
||||||
|
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||||
|
"deployCdnPath": "temp/deploy"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||||
|
"workingDir": "./temp/deploy/",
|
||||||
|
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||||
|
"container": "react-tenant-properties",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"preset": "@voitanos/jest-preset-spfx-react16",
|
||||||
|
"rootDir": "../src"
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "react-tenant-properties-client-side-solution",
|
||||||
|
"id": "d5bc38a6-0b5c-4644-9087-efa6de87ece1",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"webApiPermissionRequests": [
|
||||||
|
{
|
||||||
|
"resource": "Microsoft Graph",
|
||||||
|
"scope": "Directory.ReadWrite.All"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/react-tenant-properties.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://localhost:5432/workbench",
|
||||||
|
"api": {
|
||||||
|
"port": 5432,
|
||||||
|
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
// check if gulp dist was called
|
||||||
|
if (process.argv.indexOf('dist') !== -1) {
|
||||||
|
// add ship options to command call
|
||||||
|
process.argv.push('--ship');
|
||||||
|
}
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
const gulp = require('gulp');
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
const gulpSequence = require('gulp-sequence');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
// Create clean distrubution package
|
||||||
|
gulp.task('dist', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||||
|
// Create clean development package
|
||||||
|
gulp.task('dev', gulpSequence('clean', 'bundle', 'package-solution'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Framework Specific gulp tasks
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
build.initialize(gulp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Continuous Integration
|
||||||
|
*/
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,51 @@
|
||||||
|
{
|
||||||
|
"name": "react-tenant-properties",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"preversion": "node ./tools/pre-version.js",
|
||||||
|
"postversion": "gulp dist",
|
||||||
|
"test": "./node_modules/.bin/jest --config ./config/jest.config.json",
|
||||||
|
"test:watch": "./node_modules/.bin/jest --config ./config/jest.config.json --watchAll"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/office-ui-fabric-react-bundle": "^1.7.1",
|
||||||
|
"@microsoft/sp-core-library": "1.7.1",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.7.1",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.7.1",
|
||||||
|
"@microsoft/sp-webpart-base": "1.7.1",
|
||||||
|
"@pnp/pnpjs": "^1.3.0",
|
||||||
|
"@pnp/spfx-controls-react": "1.12.0",
|
||||||
|
"@pnp/spfx-property-controls": "1.14.1",
|
||||||
|
"@types/es6-promise": "0.0.33",
|
||||||
|
"@types/jquery": "^3.3.29",
|
||||||
|
"@types/react": "16.4.2",
|
||||||
|
"@types/react-dom": "16.0.5",
|
||||||
|
"@types/webpack-env": "1.13.1",
|
||||||
|
"jquery": "^3.3.1",
|
||||||
|
"react": "16.3.2",
|
||||||
|
"react-dom": "16.3.2"
|
||||||
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"@types/react": "16.4.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/sp-build-web": "1.7.1",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.7.1",
|
||||||
|
"@microsoft/sp-tslint-rules": "1.7.1",
|
||||||
|
"@microsoft/sp-webpart-workbench": "1.7.1",
|
||||||
|
"@types/chai": "3.4.34",
|
||||||
|
"@types/mocha": "2.2.38",
|
||||||
|
"@voitanos/jest-preset-spfx-react16": "^1.1.0",
|
||||||
|
"ajv": "~5.2.2",
|
||||||
|
"gulp": "~3.9.1",
|
||||||
|
"gulp-sequence": "1.0.0",
|
||||||
|
"jest": "^23.6.0",
|
||||||
|
"karma-junit-reporter": "^1.2.0"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface ITenantProperty {
|
||||||
|
key: string;
|
||||||
|
Comment?: string;
|
||||||
|
Description?: string;
|
||||||
|
Value: string;
|
||||||
|
}
|
|
@ -0,0 +1,116 @@
|
||||||
|
// João Mendes
|
||||||
|
// March 2019
|
||||||
|
|
||||||
|
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||||
|
import { sp, Web, } from '@pnp/sp';
|
||||||
|
import { graph, } from "@pnp/graph";
|
||||||
|
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
|
||||||
|
import { ITenantProperty } from './ITenantProperty';
|
||||||
|
|
||||||
|
const ADMIN_ROLETEMPLATE_ID = "62e90394-69f5-4237-9190-012177145e10"; // Global Admin TemplateRoleId
|
||||||
|
// Class Services
|
||||||
|
export default class spservices {
|
||||||
|
private appCatalogUrl: string = '';
|
||||||
|
constructor(private context: WebPartContext) {
|
||||||
|
// Setuo Context to PnPjs and MSGraph
|
||||||
|
sp.setup({
|
||||||
|
spfxContext: this.context
|
||||||
|
});
|
||||||
|
|
||||||
|
graph.setup({
|
||||||
|
spfxContext: this.context
|
||||||
|
});
|
||||||
|
|
||||||
|
this.onInit();
|
||||||
|
}
|
||||||
|
// OnInit Function
|
||||||
|
private async onInit() {
|
||||||
|
this.appCatalogUrl = await this.getAppCatalogUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Tenant Property
|
||||||
|
public async checkTenantProperty(newPropertyKey: string) {
|
||||||
|
let returnValue: boolean = false;
|
||||||
|
try {
|
||||||
|
const webAppCatalog: Web = new Web(this.appCatalogUrl);
|
||||||
|
const tenantProperty: any = await webAppCatalog.getStorageEntity(newPropertyKey);
|
||||||
|
console.log(tenantProperty);
|
||||||
|
if (tenantProperty && !tenantProperty['odata.null']) {
|
||||||
|
returnValue = true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
|
||||||
|
return Promise.reject(error.message);
|
||||||
|
}
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
// Add or updateTenant Property
|
||||||
|
public async setTenantProperty(newProperty: ITenantProperty) {
|
||||||
|
try {
|
||||||
|
const webAppCatalog: Web = new Web(this.appCatalogUrl);
|
||||||
|
await webAppCatalog.setStorageEntity(newProperty.key, newProperty.Value, newProperty.Description, newProperty.Comment);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Add Tenant Property
|
||||||
|
public async removeTenantProperty(newProperty: ITenantProperty) {
|
||||||
|
try {
|
||||||
|
const webAppCatalog: Web = new Web(this.appCatalogUrl);
|
||||||
|
await webAppCatalog.removeStorageEntity(newProperty.key);
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Get App Catalog
|
||||||
|
private async getAppCatalogUrl() {
|
||||||
|
try {
|
||||||
|
const webAbsoluteUrl = this.context.pageContext.web.absoluteUrl;
|
||||||
|
const apiUrl = `${webAbsoluteUrl}/_api/SP_TenantSettings_Current`;
|
||||||
|
|
||||||
|
const data: SPHttpClientResponse = await this.context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
|
||||||
|
if (data.ok) {
|
||||||
|
const results = await data.json();
|
||||||
|
if (results) {
|
||||||
|
return results.CorporateCatalogUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
console.dir(error);
|
||||||
|
return Promise.reject(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Check if user is Global Admin
|
||||||
|
public async checkUserIsGlobalAdmin() {
|
||||||
|
const myDirRolesAndGroups: any[] = await graph.me.memberOf.get();
|
||||||
|
for (const myDirRolesAndGroup of myDirRolesAndGroups) {
|
||||||
|
if (myDirRolesAndGroup.roleTemplateId && myDirRolesAndGroup.roleTemplateId === ADMIN_ROLETEMPLATE_ID) { // roleTemplateId for glabal Admin
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// get Tenant Properties
|
||||||
|
public async getTenantProperties() {
|
||||||
|
try {
|
||||||
|
const appCatalogUrl = await this.getAppCatalogUrl();
|
||||||
|
const apiUrl = `${appCatalogUrl}/_api/web/AllProperties?$select=storageentitiesindex`;
|
||||||
|
const data: SPHttpClientResponse = await this.context.spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
|
||||||
|
if (data.ok) {
|
||||||
|
const results = await data.json();
|
||||||
|
if (results && results.storageentitiesindex) {
|
||||||
|
const properties: { [key: string]: ITenantProperty } = JSON.parse(results.storageentitiesindex);
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} catch (error) {
|
||||||
|
return Promise.reject(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "fe85bc01-3650-4533-9c42-5c078fdd579c",
|
||||||
|
"alias": "TenantPropertiesWebPart",
|
||||||
|
"componentType": "WebPart",
|
||||||
|
|
||||||
|
// The "*" signifies that the version should be taken from the package.json
|
||||||
|
"version": "*",
|
||||||
|
"manifestVersion": 2,
|
||||||
|
|
||||||
|
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||||
|
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||||
|
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||||
|
"requiresCustomScript": false,
|
||||||
|
|
||||||
|
"preconfiguredEntries": [{
|
||||||
|
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||||
|
"group": { "default": "Other" },
|
||||||
|
"title": { "default": "Tenant Properties" },
|
||||||
|
"description": { "default": "Manage Tenant Properties" },
|
||||||
|
"officeFabricIconFontName": "Settings",
|
||||||
|
"properties": {
|
||||||
|
"title": "Tenant Properties"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import {
|
||||||
|
BaseClientSideWebPart,
|
||||||
|
IPropertyPaneConfiguration,
|
||||||
|
PropertyPaneTextField
|
||||||
|
} from '@microsoft/sp-webpart-base';
|
||||||
|
|
||||||
|
import * as strings from 'TenantPropertiesWebPartStrings';
|
||||||
|
import TenantProperties from './components/TenantProperties';
|
||||||
|
import { ITenantPropertiesProps } from './components/ITenantPropertiesProps';
|
||||||
|
|
||||||
|
export interface ITenantPropertiesWebPartProps {
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class TenantPropertiesWebPart extends BaseClientSideWebPart<ITenantPropertiesWebPartProps> {
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
const element: React.ReactElement<ITenantPropertiesProps> = React.createElement(
|
||||||
|
TenantProperties,
|
||||||
|
{
|
||||||
|
title: this.properties.title,
|
||||||
|
context: this.context,
|
||||||
|
displayMode: this.displayMode,
|
||||||
|
updateProperty: (value: string) => {
|
||||||
|
this.properties.title = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onDispose(): void {
|
||||||
|
ReactDom.unmountComponentAtNode(this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse('1.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
description: strings.PropertyPaneDescription
|
||||||
|
},
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: strings.BasicGroupName,
|
||||||
|
groupFields: [
|
||||||
|
PropertyPaneTextField('title', {
|
||||||
|
label: strings.TitleFieldLabel,
|
||||||
|
value: 'Tenant Properties'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
export interface IListViewItems {
|
||||||
|
key: string;
|
||||||
|
tenantPropertyDescription: string;
|
||||||
|
tenantPropertyComment:string;
|
||||||
|
tenantPropertyValue:string;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||||
|
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||||
|
export interface ITenantPropertiesProps {
|
||||||
|
title: string;
|
||||||
|
context: WebPartContext;
|
||||||
|
displayMode:DisplayMode;
|
||||||
|
updateProperty(value:string):void;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { IListViewItems } from '../components/IListViewItems';
|
||||||
|
import { panelMode } from './ITenantPropertyPanelProps';
|
||||||
|
|
||||||
|
export interface ITenantPropertiesState {
|
||||||
|
items: IListViewItems[];
|
||||||
|
isLoading:boolean;
|
||||||
|
disableCommandOption:boolean;
|
||||||
|
showPanel:boolean;
|
||||||
|
selectItem: IListViewItems;
|
||||||
|
panelMode: panelMode;
|
||||||
|
hasError: boolean;
|
||||||
|
errorMessage: string;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import {IListViewItems } from "./IListViewItems";
|
||||||
|
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||||
|
export enum panelMode {
|
||||||
|
"New",
|
||||||
|
"edit",
|
||||||
|
"Delete"
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ITenantPropertyPanelProps {
|
||||||
|
mode:panelMode;
|
||||||
|
showPanel: boolean;
|
||||||
|
TenantProperty: IListViewItems ;
|
||||||
|
onDismiss(refresh?:boolean) : void;
|
||||||
|
context: WebPartContext;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
import {IListViewItems } from "./IListViewItems";
|
||||||
|
export interface ITenantPropertyPanelSate {
|
||||||
|
showPanel:boolean;
|
||||||
|
readOnly: boolean;
|
||||||
|
visible: boolean;
|
||||||
|
multiline: boolean;
|
||||||
|
primaryButtonLabel:string;
|
||||||
|
disableButton:boolean;
|
||||||
|
tenantProperty: IListViewItems;
|
||||||
|
errorMessage:string;
|
||||||
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||||
|
|
||||||
|
.tenantProperties {
|
||||||
|
.container {
|
||||||
|
max-width: 700px;
|
||||||
|
margin: 0px auto;
|
||||||
|
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.webparttitle{
|
||||||
|
margin-top: 25px;
|
||||||
|
margin-bottom: 25px;
|
||||||
|
}
|
||||||
|
.messageError{
|
||||||
|
margin-top: 25px;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
margin-right: 25px;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
[disabled].itemLink{
|
||||||
|
color: #c8c8c8 !important;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
@include ms-Grid-row;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
background-color: $ms-color-themeDark;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
@include ms-Grid-col;
|
||||||
|
@include ms-lg10;
|
||||||
|
@include ms-xl8;
|
||||||
|
@include ms-xlPush2;
|
||||||
|
@include ms-lgPush1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
@include ms-font-xl;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subTitle {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
@include ms-font-l;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,275 @@
|
||||||
|
//
|
||||||
|
// João Mendes
|
||||||
|
// Mar 2019
|
||||||
|
//
|
||||||
|
import * as React from 'react';
|
||||||
|
import styles from './TenantProperties.module.scss';
|
||||||
|
import { ITenantPropertiesProps } from './ITenantPropertiesProps';
|
||||||
|
import { ITenantPropertiesState } from './ITenantPropertiesState';
|
||||||
|
import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
import { ListView, IViewField, SelectionMode, GroupOrder, IGrouping } from "@pnp/spfx-controls-react/lib/ListView";
|
||||||
|
import { IListViewItems } from '../components/IListViewItems';
|
||||||
|
import spservice from '../../../services/spservices';
|
||||||
|
import { ITenantProperty } from '../../../services/ITenantProperty';
|
||||||
|
import { Icon } from 'office-ui-fabric-react/lib/Icon';
|
||||||
|
import { CommandBar } from 'office-ui-fabric-react/lib/CommandBar';
|
||||||
|
import TenantProperyPanel from './TenantPropertyPanel';
|
||||||
|
import { panelMode } from './ITenantPropertyPanelProps';
|
||||||
|
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
|
||||||
|
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/Spinner';
|
||||||
|
import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle";
|
||||||
|
import * as strings from 'TenantPropertiesWebPartStrings';
|
||||||
|
|
||||||
|
// ListView Columns
|
||||||
|
const viewFields: IViewField[] = [
|
||||||
|
{
|
||||||
|
name: 'Prop',
|
||||||
|
render: ((item: IListViewItems) => {
|
||||||
|
return <Icon iconName="Tag" />;
|
||||||
|
}),
|
||||||
|
maxWidth: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
displayName: strings.ListViewColumnKeyLabel,
|
||||||
|
sorting: true,
|
||||||
|
isResizable: true,
|
||||||
|
maxWidth: 250
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'tenantPropertyValue',
|
||||||
|
displayName: strings.ListViewColumnValueLabel,
|
||||||
|
sorting: true,
|
||||||
|
isResizable: true,
|
||||||
|
maxWidth: 250
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'tenantPropertyDescription',
|
||||||
|
displayName: strings.ListViewColumnDescriptionLabel,
|
||||||
|
sorting: true,
|
||||||
|
isResizable: true,
|
||||||
|
maxWidth: 200
|
||||||
|
}
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
export default class TenantProperties extends React.Component<ITenantPropertiesProps, ITenantPropertiesState> {
|
||||||
|
|
||||||
|
private spService: spservice;
|
||||||
|
private items: IListViewItems[];
|
||||||
|
public constructor(props) {
|
||||||
|
super(props);
|
||||||
|
// Initialize state
|
||||||
|
this.state = ({
|
||||||
|
items: [],
|
||||||
|
isLoading: false,
|
||||||
|
disableCommandOption: true,
|
||||||
|
showPanel: false,
|
||||||
|
selectItem: null,
|
||||||
|
panelMode: panelMode.New,
|
||||||
|
hasError: false,
|
||||||
|
errorMessage: ''
|
||||||
|
});
|
||||||
|
// Init class services
|
||||||
|
this.spService = new spservice(this.props.context);
|
||||||
|
// Register event handlers
|
||||||
|
this._getSelection = this._getSelection.bind(this);
|
||||||
|
this.onNewItem = this.onNewItem.bind(this);
|
||||||
|
this.onEditItem = this.onEditItem.bind(this);
|
||||||
|
this.onDeleteItem = this.onDeleteItem.bind(this);
|
||||||
|
this.onDismissPanel = this.onDismissPanel.bind(this);
|
||||||
|
this.onRefresh = this.onRefresh.bind(this);
|
||||||
|
}
|
||||||
|
// Get Selection Item from List
|
||||||
|
private _getSelection(items: IListViewItems[]) {
|
||||||
|
if (items.length > 0) {
|
||||||
|
this.setState({
|
||||||
|
disableCommandOption: false,
|
||||||
|
selectItem: items[0]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
disableCommandOption: true,
|
||||||
|
selectItem: null,
|
||||||
|
showPanel: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Panel Dismiss CallBack
|
||||||
|
// @param refresh refresh list?
|
||||||
|
public async onDismissPanel(refresh?: boolean) {
|
||||||
|
this.setState({
|
||||||
|
showPanel: false
|
||||||
|
});
|
||||||
|
if (refresh) {
|
||||||
|
await this.loadTenantProperties();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// On New Item
|
||||||
|
private onNewItem(e: React.MouseEvent<HTMLElement>) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.setState({
|
||||||
|
panelMode: panelMode.New,
|
||||||
|
showPanel: true,
|
||||||
|
selectItem: { key: '', tenantPropertyValue: '', tenantPropertyDescription: '', tenantPropertyComment: '' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// On Delete
|
||||||
|
private onDeleteItem(e: React.MouseEvent<HTMLElement>) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.setState({
|
||||||
|
panelMode: panelMode.Delete,
|
||||||
|
showPanel: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// On Edit item
|
||||||
|
private onEditItem(e: React.MouseEvent<HTMLElement>) {
|
||||||
|
e.preventDefault();
|
||||||
|
this.setState({
|
||||||
|
panelMode: panelMode.edit,
|
||||||
|
showPanel: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Load Tenant Properties
|
||||||
|
private async loadTenantProperties() {
|
||||||
|
this.items = [];
|
||||||
|
this.setState({ isLoading: true });
|
||||||
|
try {
|
||||||
|
// check if user is Teanant Global Admin
|
||||||
|
const isGlobalAdmin = await this.spService.checkUserIsGlobalAdmin();
|
||||||
|
if (isGlobalAdmin) {
|
||||||
|
// Get Tenant Properties
|
||||||
|
const properties: ITenantProperty = await this.spService.getTenantProperties();
|
||||||
|
if (properties) {
|
||||||
|
const keys: string[] = Object.keys(properties);
|
||||||
|
keys.map((key: string): any => {
|
||||||
|
const property: ITenantProperty = properties[key];
|
||||||
|
this.items.push(
|
||||||
|
{
|
||||||
|
key: key,
|
||||||
|
tenantPropertyValue: property.Value,
|
||||||
|
tenantPropertyDescription: property.Description,
|
||||||
|
tenantPropertyComment: property.Comment
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.setState({ items: this.items, isLoading: false, disableCommandOption: true });
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
items: this.items,
|
||||||
|
hasError: true,
|
||||||
|
errorMessage: strings.ErrorMessageUserNotAdmin,
|
||||||
|
isLoading: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
this.setState({
|
||||||
|
items: this.items,
|
||||||
|
hasError: true,
|
||||||
|
errorMessage: error.message,
|
||||||
|
isLoading: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// Refresh
|
||||||
|
public onRefresh(ev: React.MouseEvent<HTMLElement>) {
|
||||||
|
ev.preventDefault();
|
||||||
|
// LoadTenantProperties
|
||||||
|
this.loadTenantProperties();
|
||||||
|
}
|
||||||
|
// Component Did Mount
|
||||||
|
public async componentDidMount() {
|
||||||
|
// LoadTenantProperties
|
||||||
|
await this.loadTenantProperties();
|
||||||
|
}
|
||||||
|
// On Render
|
||||||
|
public render(): React.ReactElement<ITenantPropertiesProps> {
|
||||||
|
return (
|
||||||
|
<div className={styles.tenantProperties}>
|
||||||
|
<WebPartTitle displayMode={this.props.displayMode}
|
||||||
|
title={this.props.title}
|
||||||
|
className={styles.webparttitle}
|
||||||
|
updateProperty={this.props.updateProperty} />
|
||||||
|
{
|
||||||
|
this.state.isLoading ?
|
||||||
|
<Spinner size={SpinnerSize.large} label={strings.LoadingLabel} ariaLive="assertive" />
|
||||||
|
:
|
||||||
|
this.state.hasError ?
|
||||||
|
<MessageBar
|
||||||
|
messageBarType={MessageBarType.error}>
|
||||||
|
<span>{this.state.errorMessage}</span>
|
||||||
|
</MessageBar>
|
||||||
|
:
|
||||||
|
<div style={{ marginBottom: 10 }}>
|
||||||
|
<CommandBar
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
key: 'newItem',
|
||||||
|
name: strings.CommandbarNewLabel,
|
||||||
|
iconProps: {
|
||||||
|
iconName: 'Add'
|
||||||
|
},
|
||||||
|
onClick: this.onNewItem,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'edit',
|
||||||
|
name: strings.CommandbarEditLabel,
|
||||||
|
iconProps: {
|
||||||
|
iconName: 'Edit'
|
||||||
|
},
|
||||||
|
onClick: this.onEditItem,
|
||||||
|
disabled: this.state.disableCommandOption,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'delete',
|
||||||
|
name: strings.CommandbarDeleteLabel,
|
||||||
|
iconProps: {
|
||||||
|
iconName: 'Delete'
|
||||||
|
},
|
||||||
|
onClick: this.onDeleteItem,
|
||||||
|
disabled: this.state.disableCommandOption,
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
farItems={[
|
||||||
|
{
|
||||||
|
key: 'refresh',
|
||||||
|
name: strings.CommandbarRefreshLabel,
|
||||||
|
iconProps: {
|
||||||
|
iconName: 'Refresh'
|
||||||
|
},
|
||||||
|
onClick: this.onRefresh,
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
!this.state.hasError && !this.state.isLoading &&
|
||||||
|
<ListView
|
||||||
|
items={this.state.items}
|
||||||
|
viewFields={viewFields}
|
||||||
|
compact={false}
|
||||||
|
selectionMode={SelectionMode.single}
|
||||||
|
selection={this._getSelection}
|
||||||
|
showFilter={true}
|
||||||
|
filterPlaceHolder={strings.SearchPlaceholder}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
{
|
||||||
|
this.state.showPanel &&
|
||||||
|
<TenantProperyPanel
|
||||||
|
mode={this.state.panelMode}
|
||||||
|
TenantProperty={this.state.selectItem}
|
||||||
|
onDismiss={this.onDismissPanel}
|
||||||
|
showPanel={this.state.showPanel}
|
||||||
|
context={this.props.context}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,225 @@
|
||||||
|
// João Mendes
|
||||||
|
// Mar 2019
|
||||||
|
import * as React from 'react';
|
||||||
|
import styles from './TenantProperties.module.scss';
|
||||||
|
import { ITenantPropertyPanelProps, panelMode } from './ITenantPropertyPanelProps';
|
||||||
|
import { ITenantPropertyPanelSate } from './ITenantPropertyPanelState';
|
||||||
|
import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
import spservice from '../../../services/spservices';
|
||||||
|
|
||||||
|
import * as strings from 'TenantPropertiesWebPartStrings';
|
||||||
|
import { TextField } from 'office-ui-fabric-react/lib/TextField';
|
||||||
|
import { Panel, PanelType } from 'office-ui-fabric-react/lib/Panel';
|
||||||
|
import { Dialog, DialogType, DialogFooter } from 'office-ui-fabric-react/lib/Dialog';
|
||||||
|
import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/Button';
|
||||||
|
|
||||||
|
|
||||||
|
// Display Tenant Property Panel Component
|
||||||
|
export default class TenantPropertyPanel extends React.Component<ITenantPropertyPanelProps, ITenantPropertyPanelSate> {
|
||||||
|
private spService: spservice;
|
||||||
|
public constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = ({
|
||||||
|
showPanel: false,
|
||||||
|
readOnly: true,
|
||||||
|
visible: true,
|
||||||
|
multiline: true,
|
||||||
|
primaryButtonLabel: strings.PrimaryButtonLabelSave,
|
||||||
|
disableButton: true,
|
||||||
|
tenantProperty: null,
|
||||||
|
errorMessage: ''
|
||||||
|
});
|
||||||
|
// Init class services
|
||||||
|
this.spService = new spservice(this.props.context);
|
||||||
|
this.onGetErrorMessageKey = this.onGetErrorMessageKey.bind(this);
|
||||||
|
this.onGetErrorMessageValue = this.onGetErrorMessageValue.bind(this);
|
||||||
|
this.onGetErrorMessageDescription = this.onGetErrorMessageDescription.bind(this);
|
||||||
|
this.onGetErrorMessageComment = this.onGetErrorMessageComment.bind(this);
|
||||||
|
this.onSave = this.onSave.bind(this);
|
||||||
|
this.onCancel = this.onCancel.bind(this);
|
||||||
|
this.onChanged = this.onChanged.bind(this);
|
||||||
|
}
|
||||||
|
// Cancel Panel
|
||||||
|
private onCancel(ev: React.MouseEvent<HTMLButtonElement>) {
|
||||||
|
ev.preventDefault();
|
||||||
|
this.props.onDismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Save / Delete
|
||||||
|
private async onSave(ev: React.MouseEvent<HTMLButtonElement>) {
|
||||||
|
ev.preventDefault();
|
||||||
|
switch (this.props.mode) {
|
||||||
|
// add Tenant Property
|
||||||
|
case (panelMode.New):
|
||||||
|
try{
|
||||||
|
const result = await this.spService.setTenantProperty({
|
||||||
|
key: this.state.tenantProperty.key,
|
||||||
|
Value:this.state.tenantProperty.tenantPropertyValue,
|
||||||
|
Description: this.state.tenantProperty.tenantPropertyDescription,
|
||||||
|
Comment: this.state.tenantProperty.tenantPropertyComment
|
||||||
|
});
|
||||||
|
result ? this.props.onDismiss(true) : null;
|
||||||
|
}catch(error){
|
||||||
|
this.setState({errorMessage:error});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// edit Tenant Property
|
||||||
|
case (panelMode.edit):
|
||||||
|
try{
|
||||||
|
const result = await this.spService.setTenantProperty({
|
||||||
|
key: this.state.tenantProperty.key,
|
||||||
|
Value:this.state.tenantProperty.tenantPropertyValue,
|
||||||
|
Description: this.state.tenantProperty.tenantPropertyDescription,
|
||||||
|
Comment: this.state.tenantProperty.tenantPropertyComment
|
||||||
|
});
|
||||||
|
result ? this.props.onDismiss(true) : null;
|
||||||
|
}catch(error){
|
||||||
|
this.setState({errorMessage:error});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// Remove Tenant Property
|
||||||
|
case (panelMode.Delete):
|
||||||
|
try{
|
||||||
|
const result = await this.spService.removeTenantProperty({
|
||||||
|
key: this.state.tenantProperty.key,
|
||||||
|
Value:this.state.tenantProperty.tenantPropertyValue,
|
||||||
|
Description: this.state.tenantProperty.tenantPropertyDescription,
|
||||||
|
Comment: this.state.tenantProperty.tenantPropertyComment
|
||||||
|
});
|
||||||
|
result ? this.props.onDismiss(true) : null;
|
||||||
|
}catch(error){
|
||||||
|
this.setState({errorMessage:error});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Validate Key
|
||||||
|
private async onGetErrorMessageKey(value: string) {
|
||||||
|
const _tenantProperty = this.state.tenantProperty;
|
||||||
|
let returnvalue: string = '';
|
||||||
|
if (value.trim().length > 0) {
|
||||||
|
_tenantProperty.key = value;
|
||||||
|
const tenantPropertyExist: boolean = await this.spService.checkTenantProperty(_tenantProperty.key);
|
||||||
|
if (tenantPropertyExist && this.props.mode === panelMode.New) {
|
||||||
|
returnvalue = strings.messageTenantExist;
|
||||||
|
this.setState({ disableButton: true, tenantProperty: _tenantProperty });
|
||||||
|
} else {
|
||||||
|
returnvalue = '';
|
||||||
|
this.setState({tenantProperty: _tenantProperty });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_tenantProperty.key = value;
|
||||||
|
this.setState({ disableButton: true, tenantProperty: _tenantProperty });
|
||||||
|
}
|
||||||
|
return returnvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Value
|
||||||
|
private onGetErrorMessageValue(value: string) {
|
||||||
|
let returnvalue: string = '';
|
||||||
|
const _tenantProperty = this.state.tenantProperty;
|
||||||
|
if (value.trim().length > 0) {
|
||||||
|
_tenantProperty.tenantPropertyValue = value;
|
||||||
|
this.setState({ disableButton: false, tenantProperty: _tenantProperty });
|
||||||
|
} else {
|
||||||
|
_tenantProperty.tenantPropertyValue = value;
|
||||||
|
this.setState({ disableButton: true, tenantProperty: _tenantProperty });
|
||||||
|
}
|
||||||
|
return returnvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Description
|
||||||
|
private onGetErrorMessageDescription(value: string) {
|
||||||
|
let returnvalue: string = '';
|
||||||
|
const _tenantProperty = this.state.tenantProperty;
|
||||||
|
_tenantProperty.tenantPropertyDescription = value;
|
||||||
|
this.setState({ tenantProperty: _tenantProperty });
|
||||||
|
|
||||||
|
return returnvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate Comment
|
||||||
|
private onGetErrorMessageComment(value: string) {
|
||||||
|
let returnvalue: string = '';
|
||||||
|
const _tenantProperty = this.state.tenantProperty;
|
||||||
|
_tenantProperty.tenantPropertyComment = value;
|
||||||
|
this.setState({ tenantProperty: _tenantProperty });
|
||||||
|
|
||||||
|
return returnvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private onChanged(value: string) {
|
||||||
|
alert(value);
|
||||||
|
}
|
||||||
|
// Component DidMount
|
||||||
|
public async componentDidMount() {
|
||||||
|
this.setState({ tenantProperty: this.props.TenantProperty });
|
||||||
|
if (this.props.mode === panelMode.edit || this.props.mode === panelMode.New) {
|
||||||
|
this.setState({ readOnly: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Render
|
||||||
|
public render(): React.ReactElement<ITenantPropertyPanelProps> {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Panel
|
||||||
|
isOpen={this.props.showPanel}
|
||||||
|
type={PanelType.smallFixedFar}
|
||||||
|
onDismiss={this.props.onDismiss}
|
||||||
|
headerText={this.props.mode == panelMode.edit || this.props.mode == panelMode.New ? strings.PanelHeaderTextEdit : strings.PanelHeaderTextDelete}
|
||||||
|
>
|
||||||
|
<TextField
|
||||||
|
label={strings.ListViewColumnKeyLabel}
|
||||||
|
readOnly={this.state.readOnly}
|
||||||
|
required={true}
|
||||||
|
multiline={this.state.multiline}
|
||||||
|
value={this.state.tenantProperty ? this.state.tenantProperty.key : ''}
|
||||||
|
deferredValidationTime={1500}
|
||||||
|
onGetErrorMessage={this.onGetErrorMessageKey} />
|
||||||
|
<TextField
|
||||||
|
label={strings.ListViewColumnValueLabel}
|
||||||
|
multiline={this.state.multiline}
|
||||||
|
readOnly={this.state.readOnly}
|
||||||
|
required={true}
|
||||||
|
deferredValidationTime={1500}
|
||||||
|
value={this.state.tenantProperty ? this.state.tenantProperty.tenantPropertyValue : ''}
|
||||||
|
onGetErrorMessage={this.onGetErrorMessageValue} />
|
||||||
|
<TextField
|
||||||
|
label={strings.ListViewColumnDescriptionLabel}
|
||||||
|
multiline={this.state.multiline}
|
||||||
|
readOnly={this.state.readOnly}
|
||||||
|
deferredValidationTime={1500}
|
||||||
|
onGetErrorMessage={this.onGetErrorMessageDescription}
|
||||||
|
validateOnFocusOut
|
||||||
|
defaultValue={this.state.tenantProperty ? this.state.tenantProperty.tenantPropertyDescription : ''}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
label={strings.ListViewColumnCommentLabel}
|
||||||
|
multiline={this.state.multiline}
|
||||||
|
readOnly={this.state.readOnly}
|
||||||
|
validateOnFocusOut
|
||||||
|
onGetErrorMessage={this.onGetErrorMessageComment}
|
||||||
|
deferredValidationTime={1500}
|
||||||
|
defaultValue={this.state.tenantProperty ? this.state.tenantProperty.tenantPropertyComment : ''}
|
||||||
|
/>
|
||||||
|
<div className={styles.messageError}>
|
||||||
|
<span>
|
||||||
|
{this.state.errorMessage}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<DialogFooter>
|
||||||
|
<PrimaryButton
|
||||||
|
onClick={this.onSave}
|
||||||
|
text={this.props.mode == panelMode.edit || this.props.mode == panelMode.New ? strings.PrimaryButtonLabelSave : strings.PrimaryButtonLabelDelete}
|
||||||
|
disabled={this.state.disableButton}
|
||||||
|
/>
|
||||||
|
<DefaultButton onClick={this.onCancel} text={strings.DefaultButtonLabel} />
|
||||||
|
</DialogFooter>
|
||||||
|
</Panel>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "Properties",
|
||||||
|
"BasicGroupName": "Group Name",
|
||||||
|
"TitleFieldLabel": "Title",
|
||||||
|
"ListViewColumnKeyLabel": "Key",
|
||||||
|
"ListViewColumnValueLabel": "Value",
|
||||||
|
"ListViewColumnDescriptionLabel": "Description",
|
||||||
|
"ListViewColumnCommentLabel": "Comment",
|
||||||
|
"ErrorMessageUserNotAdmin": "User is not Tenant Admin to managed Tenant Properties",
|
||||||
|
"LoadingLabel":"Loading...",
|
||||||
|
"CommandbarNewLabel":"New",
|
||||||
|
"CommandbarEditLabel": "Edit",
|
||||||
|
"CommandbarDeleteLabel": "Delete",
|
||||||
|
"CommandbarRefreshLabel": "Refresh",
|
||||||
|
"SearchPlaceholder": "Search...",
|
||||||
|
"PrimaryButtonLabelSave":"Save",
|
||||||
|
"PrimaryButtonLabelDelete":"Delete",
|
||||||
|
"DefaultButtonLabel":"Cancel",
|
||||||
|
"PanelHeaderTextEdit":"Add / Edit Tenant Property",
|
||||||
|
"PanelHeaderTextDelete":"Delete Tenant Property",
|
||||||
|
"messageTenantExist": "A Tenant Property with this key already exists"
|
||||||
|
}
|
||||||
|
});
|
27
samples/react-tenant-properties/src/webparts/tenantProperties/loc/mystrings.d.ts
vendored
Normal file
27
samples/react-tenant-properties/src/webparts/tenantProperties/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
declare interface ITenantPropertiesWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
BasicGroupName: string;
|
||||||
|
TitleFieldLabel: string;
|
||||||
|
ListViewColumnKeyLabel:string;
|
||||||
|
ListViewColumnValueLabel:string;
|
||||||
|
ListViewColumnDescriptionLabel:string;
|
||||||
|
ListViewColumnCommentLabel:string;
|
||||||
|
ErrorMessageUserNotAdmin:string;
|
||||||
|
LoadingLabel:string;
|
||||||
|
CommandbarNewLabel:string;
|
||||||
|
CommandbarEditLabel:string;
|
||||||
|
CommandbarDeleteLabel:string;
|
||||||
|
CommandbarRefreshLabel:string;
|
||||||
|
SearchPlaceholder:string;
|
||||||
|
PrimaryButtonLabelSave:string;
|
||||||
|
PrimaryButtonLabelDelete:string;
|
||||||
|
DefaultButtonLabel:string;
|
||||||
|
PanelHeaderTextEdit:string,
|
||||||
|
PanelHeaderTextDelete:string,
|
||||||
|
messageTenantExist:string
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'TenantPropertiesWebPartStrings' {
|
||||||
|
const strings: ITenantPropertiesWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* This script updates the package-solution version analogue to the
|
||||||
|
* the package.json file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (process.env.npm_package_version === undefined) {
|
||||||
|
|
||||||
|
throw 'Package version cannot be evaluated';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// define path to package-solution file
|
||||||
|
const solution = './config/package-solution.json',
|
||||||
|
teams = './teams/manifest.json';
|
||||||
|
|
||||||
|
// require filesystem instanc
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
// get next automated package version from process variable
|
||||||
|
const nextPkgVersion = process.env.npm_package_version;
|
||||||
|
|
||||||
|
// make sure next build version match
|
||||||
|
const nextVersion = nextPkgVersion.indexOf('-') === -1 ?
|
||||||
|
nextPkgVersion : nextPkgVersion.split('-')[0];
|
||||||
|
|
||||||
|
// Update version in SPFx package-solution if exists
|
||||||
|
if (fs.existsSync(solution)) {
|
||||||
|
|
||||||
|
// read package-solution file
|
||||||
|
const solutionFileContent = fs.readFileSync(solution, 'UTF-8');
|
||||||
|
// parse file as json
|
||||||
|
const solutionContents = JSON.parse(solutionFileContent);
|
||||||
|
|
||||||
|
// set property of version to next version
|
||||||
|
solutionContents.solution.version = nextVersion + '.0';
|
||||||
|
|
||||||
|
// save file
|
||||||
|
fs.writeFileSync(
|
||||||
|
solution,
|
||||||
|
// convert file back to proper json
|
||||||
|
JSON.stringify(solutionContents, null, 2),
|
||||||
|
'UTF-8');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update version in teams manifest if exists
|
||||||
|
if (fs.existsSync(teams)) {
|
||||||
|
|
||||||
|
// read package-solution file
|
||||||
|
const teamsManifestContent = fs.readFileSync(teams, 'UTF-8');
|
||||||
|
// parse file as json
|
||||||
|
const teamsContent = JSON.parse(teamsManifestContent);
|
||||||
|
|
||||||
|
// set property of version to next version
|
||||||
|
teamsContent.version = nextVersion;
|
||||||
|
|
||||||
|
// save file
|
||||||
|
fs.writeFileSync(
|
||||||
|
teams,
|
||||||
|
// convert file back to proper json
|
||||||
|
JSON.stringify(teamsContent, null, 2),
|
||||||
|
'UTF-8');
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@microsoft"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"es6-promise",
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es5",
|
||||||
|
"dom",
|
||||||
|
"es2015.collection"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts", "src/webparts/tenantProperties/components/TenantPropertyPanel.tsx"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"lib"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||||
|
"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-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,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue