Merge branch 'thememanager' of https://github.com/skaggej/sp-dev-fx-webparts into PR891
This commit is contained in:
commit
badef6e29e
|
@ -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,11 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"environment": "onprem19",
|
||||||
|
"version": "1.8.1",
|
||||||
|
"libraryName": "js-theme-manager-2019",
|
||||||
|
"libraryId": "13993f26-4e3c-4518-9ef0-97da21759508",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
# Modern Experience Theme Manager
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
This sample web part provides a user interface for applying a Modern Experience theme in SharePoint 2019 on-premises.
|
||||||
|
|
||||||
|
The Theme Palette can be generated using the UI Fabric Theme Generator at: https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/pull/9318/merge/theming-designer/index.html.
|
||||||
|
|
||||||
|
<h2>The following feature is available within this sample:</h2>
|
||||||
|
|
||||||
|
<b>Apply a theme:</b><br>
|
||||||
|
By providing a Site Collection URL, along with a theme name and palette, the theme will be applied to the Site Collection directly without being added to the tenant Company Theme options.<br>
|
||||||
|
NOTE: This is a great option to provide theme management of a Site Collection without adding a theme to the "Company Themes" choices within the "Change the Look" options at the tenant level. The web part could be added to a Site Collection App Catalog to ensure availability of the web part is only available to those approved for theme management.
|
||||||
|
![preview](./assets/apply-a-theme.png)
|
||||||
|
|
||||||
|
|
||||||
|
## Used SharePoint Framework Version
|
||||||
|
![drop](https://img.shields.io/badge/drop-1.8.2-orange.svg)
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
* [SharePoint Framework](https:/dev.office.com/sharepoint)
|
||||||
|
* SharePoint 2019 on-premises
|
||||||
|
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
js-theme-manager-2019 | David Warner II ([@DavidWarnerII](https://twitter.com/davidwarnerii) / [Warner Digital](http://warner.digital))
|
||||||
|
js-theme-manager-2019 | Beau Cameron ([@Beau__Cameron](https://twitter.com/@Beau__Cameron) / [Blog](https://beaucameron.net/))
|
||||||
|
js-theme-manager-2019 | Biju Basheer
|
||||||
|
js-theme-manager-2019 | Eric Skaggs ([@skaggej](https://twitter.com/skaggej) / [ericskaggs.net](http://www.ericskaggs.net/))
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
2019.0.0.0|June 17, 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 serve`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Features
|
||||||
|
This Web Part illustrates the following concepts on top of the SharePoint Framework:
|
||||||
|
|
||||||
|
- Using the SharePoint Online REST API to apply Modern Experience Themes
|
||||||
|
|
||||||
|
## Additional Information:
|
||||||
|
|
||||||
|
- [Office UI Fabric Theme Palette Generator](https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/pull/9318/merge/theming-designer/index.html)
|
||||||
|
|
||||||
|
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/js-theme-manager-2019" />
|
Binary file not shown.
After Width: | Height: | Size: 37 KiB |
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"modern-theme-manager-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/modernThemeManager/ModernThemeManagerWebPart.js",
|
||||||
|
"manifest": "./src/webparts/modernThemeManager/ModernThemeManagerWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"ModernThemeManagerWebPartStrings": "lib/webparts/modernThemeManager/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": "js-theme-manager-2019",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "js-theme-manager-2019-client-side-solution",
|
||||||
|
"id": "a828ebcf-33a4-478c-99d6-de70c11a6762",
|
||||||
|
"version": "2019.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/js-theme-manager-2019.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,7 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const gulp = require('gulp');
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"name": "js-theme-manager-2019",
|
||||||
|
"version": "2019.0.0",
|
||||||
|
"private": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/sp-core-library": "~1.4.0",
|
||||||
|
"@microsoft/sp-webpart-base": "~1.4.0",
|
||||||
|
"@microsoft/sp-lodash-subset": "~1.4.0",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "~1.4.0",
|
||||||
|
"@types/webpack-env": "1.13.1",
|
||||||
|
"@types/es6-promise": "0.0.33"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/sp-build-web": "~1.4.1",
|
||||||
|
"@microsoft/sp-module-interfaces": "~1.4.1",
|
||||||
|
"@microsoft/sp-webpart-workbench": "~1.4.1",
|
||||||
|
"gulp": "~3.9.1",
|
||||||
|
"@types/chai": "3.4.34",
|
||||||
|
"@types/mocha": "2.2.38",
|
||||||
|
"ajv": "~5.2.2"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "b707d69b-a546-4915-8d0d-a60b95f1d9fc",
|
||||||
|
"alias": "ModernThemeManagerWebPart",
|
||||||
|
"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": "Modern Theme Manager" },
|
||||||
|
"description": { "default": "Modern Theme Manager description" },
|
||||||
|
"officeFabricIconFontName": "Page",
|
||||||
|
"properties": {
|
||||||
|
"description": "Modern Theme Manager"
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,120 @@
|
||||||
|
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||||
|
|
||||||
|
.jsGenericWebpartThemeGenerator {
|
||||||
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row {
|
||||||
|
@include ms-Grid-row;
|
||||||
|
@include ms-fontColor-white;
|
||||||
|
background-color: $ms-color-themeDark;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
border:0px solid;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
display: block;
|
||||||
|
width:300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.textarea {
|
||||||
|
display: block;
|
||||||
|
width:300px;
|
||||||
|
height:255px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.siteurl {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
width:300px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#availableThemesSelect {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hide{
|
||||||
|
display:none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.show {
|
||||||
|
display: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.genericWrapper {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
#themeSelectWrapper,
|
||||||
|
#themeNameWrapper,
|
||||||
|
#themePaletteWrapper,
|
||||||
|
#themeSiteURLWrapper {
|
||||||
|
margin-left:25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.themeGeneratorURL {
|
||||||
|
color: "[theme: themePrimary, default: #fff]";
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
// Our button
|
||||||
|
text-decoration: none;
|
||||||
|
height: 32px;
|
||||||
|
|
||||||
|
// Primary Button
|
||||||
|
min-width: 80px;
|
||||||
|
background-color: $ms-color-themePrimary;
|
||||||
|
border-color: $ms-color-themePrimary;
|
||||||
|
color: $ms-color-white;
|
||||||
|
|
||||||
|
// Basic Button
|
||||||
|
outline: transparent;
|
||||||
|
position: relative;
|
||||||
|
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
font-weight: $ms-font-weight-regular;
|
||||||
|
border-width: 0;
|
||||||
|
text-align: center;
|
||||||
|
cursor: pointer;
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0 16px;
|
||||||
|
margin-top: 10px;
|
||||||
|
margin-left:25px;
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-weight: $ms-font-weight-semibold;
|
||||||
|
font-size: $ms-font-size-m;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
margin: 0 4px;
|
||||||
|
vertical-align: top;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,412 @@
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import {
|
||||||
|
BaseClientSideWebPart,
|
||||||
|
IPropertyPaneConfiguration,
|
||||||
|
PropertyPaneTextField
|
||||||
|
} from '@microsoft/sp-webpart-base';
|
||||||
|
import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
|
||||||
|
import styles from './ModernThemeManagerWebPart.module.scss';
|
||||||
|
import * as strings from 'ModernThemeManagerWebPartStrings';
|
||||||
|
|
||||||
|
import { IDigestCache, DigestCache } from '@microsoft/sp-http';
|
||||||
|
import { SPHttpClient, SPHttpClientResponse, ISPHttpClientOptions } from '@microsoft/sp-http';
|
||||||
|
|
||||||
|
export interface IModernThemeManagerWebPartProps {
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class ModernThemeManagerWebPart extends BaseClientSideWebPart<IModernThemeManagerWebPartProps> {
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
this.domElement.innerHTML = `
|
||||||
|
<div class="${ styles.jsGenericWebpartThemeGenerator}">
|
||||||
|
<div class="${ styles.container}">
|
||||||
|
<div class="${ styles.row}">
|
||||||
|
<div class="${ styles.column}">
|
||||||
|
<div class="${ styles.title}">Modern Experience SharePoint Theme Manager</div>
|
||||||
|
<a class="${ styles.themeGeneratorURL}" href="https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/pull/9318/merge/theming-designer/index.html" target="_blank">
|
||||||
|
UI Fabric Theme Generator
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="${ styles.hide}">
|
||||||
|
<p class="${ styles.subTitle}">Theme Actions</p>
|
||||||
|
<label class="${ styles.radio}"><input type="radio" name="themeAction" value="create"> Create a theme</label>
|
||||||
|
<label class="${ styles.radio}"><input type="radio" name="themeAction" value="update"> Update a theme</label>
|
||||||
|
<label class="${ styles.radio}"><input type="radio" name="themeAction" value="delete"> Delete a theme</label>
|
||||||
|
<label class="${ styles.radio}"><input type="radio" name="themeAction" value="apply"> Apply a theme</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p class="${ styles.subTitle}">Theme Actions</p>
|
||||||
|
<label class="${ styles.radio}"><input type="radio" name="themeAction" value="apply"> Apply a theme</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="${ styles.hide} ${styles.genericWrapper}" id="${styles.themeSelectWrapper}">
|
||||||
|
<p class="${ styles.subTitle}">Available Themes</p>
|
||||||
|
<select id="${ styles.availableThemesSelect}" name="availableThemes">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="${ styles.hide} ${styles.genericWrapper}" id="${styles.themeNameWrapper}">
|
||||||
|
<p class="${ styles.subTitle}">Theme Name</p>
|
||||||
|
<div>
|
||||||
|
<input id="${ styles.input}" class="${styles.input}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="${ styles.hide} ${styles.genericWrapper}" id="${styles.themePaletteWrapper}">
|
||||||
|
<p class="${ styles.subTitle}">Theme Palette</p>
|
||||||
|
<div>
|
||||||
|
<textarea id="${ styles.textarea}" class="${styles.textarea}"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="${ styles.hide} ${styles.genericWrapper}" id="${styles.themeSiteURLWrapper}">
|
||||||
|
<p class="${ styles.subTitle}">Relative Site URL (ex: "/sites/SiteCollectionName")</p>
|
||||||
|
<div>
|
||||||
|
<input id="${ styles.siteurl}" class="${styles.siteurl}">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="createTheme" class="${ styles.button} ${styles.hide}">
|
||||||
|
<span class="${ styles.label}">Create Theme</span>
|
||||||
|
</div>
|
||||||
|
<div id="updateTheme" class="${ styles.button} ${styles.hide}">
|
||||||
|
<span class="${ styles.label}">Update Theme</span>
|
||||||
|
</div>
|
||||||
|
<div id="deleteTheme" class="${ styles.button} ${styles.hide}">
|
||||||
|
<span class="${ styles.label}">Delete Theme</span>
|
||||||
|
</div>
|
||||||
|
<div id="applyTheme" class="${ styles.button} ${styles.hide}">
|
||||||
|
<span class="${ styles.label}">Apply Theme</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
|
this.setupClickEvent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Create event listeners for Radio & Buttons
|
||||||
|
***** *****/
|
||||||
|
public setupClickEvent(): void {
|
||||||
|
|
||||||
|
let btnCreateTheme = document.getElementById("createTheme");
|
||||||
|
btnCreateTheme.addEventListener("click", (e: Event) => this.createTheme());
|
||||||
|
|
||||||
|
let btnUpdateTheme = document.getElementById("updateTheme");
|
||||||
|
btnUpdateTheme.addEventListener("click", (e: Event) => this.updateTheme());
|
||||||
|
|
||||||
|
let btnDeleteTheme = document.getElementById("deleteTheme");
|
||||||
|
btnDeleteTheme.addEventListener("click", (e: Event) => this.deleteTheme());
|
||||||
|
|
||||||
|
let btnApplyTheme = document.getElementById("applyTheme");
|
||||||
|
btnApplyTheme.addEventListener("click", (e: Event) => this.applyThemeNew());
|
||||||
|
|
||||||
|
let radioThemeActions = document.getElementsByName("themeAction");
|
||||||
|
let parent = this;
|
||||||
|
for (var i = 0, max = radioThemeActions.length; i < max; i++) {
|
||||||
|
radioThemeActions[i].onclick = function () {
|
||||||
|
let selectedValue = (<HTMLInputElement>this).value;
|
||||||
|
if (selectedValue == 'delete') {
|
||||||
|
parent.displayDeleteOptions();
|
||||||
|
}
|
||||||
|
else if (selectedValue == 'create') {
|
||||||
|
parent.displayCreateOptions();
|
||||||
|
}
|
||||||
|
else if (selectedValue == 'update') {
|
||||||
|
parent.displayUpdateOptions();
|
||||||
|
}
|
||||||
|
else if (selectedValue == 'apply') {
|
||||||
|
parent.displayApplyOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Hide All Wrappers:
|
||||||
|
Generic method for hiding all of the form elements
|
||||||
|
***** *****/
|
||||||
|
public hideAllWrappers(): void {
|
||||||
|
|
||||||
|
// Hide any other elements that might have been displayed
|
||||||
|
document.getElementById(styles.themeNameWrapper).classList.add(styles.hide);
|
||||||
|
document.getElementById(styles.themePaletteWrapper).classList.add(styles.hide);
|
||||||
|
let wrappers = document.getElementsByClassName(styles.genericWrapper);
|
||||||
|
for (let i = 0; i < wrappers.length; i++) {
|
||||||
|
wrappers[i].classList.add(styles.hide);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let buttons = document.getElementsByClassName(styles.button);
|
||||||
|
for (let i = 0; i < buttons.length; i++) {
|
||||||
|
buttons[i].classList.add(styles.hide);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Display Update Options:
|
||||||
|
This method is used to display the form elements for the Theme Update Options.
|
||||||
|
***** *****/
|
||||||
|
public displayUpdateOptions(): void {
|
||||||
|
// Hide all wrappers
|
||||||
|
this.hideAllWrappers();
|
||||||
|
|
||||||
|
this.populateExistingThemes("/_api/thememanager/GetTenantThemingOptions", {}).then((success: boolean) => {
|
||||||
|
if (success) {
|
||||||
|
// Display the dropdown.
|
||||||
|
document.getElementById(styles.themeSelectWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById(styles.themePaletteWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById('updateTheme').classList.remove(styles.hide);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Display Create Options:
|
||||||
|
This method is used to display the form elements for the Theme Creation Options.
|
||||||
|
***** *****/
|
||||||
|
public displayCreateOptions(): void {
|
||||||
|
|
||||||
|
// Hide all wrappers
|
||||||
|
this.hideAllWrappers();
|
||||||
|
|
||||||
|
// Display the dropdown.
|
||||||
|
document.getElementById(styles.themeNameWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById(styles.themePaletteWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById('createTheme').classList.remove(styles.hide);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Display Delete Options:
|
||||||
|
This method is used to display the form elements for the Theme Deletion Options.
|
||||||
|
***** *****/
|
||||||
|
public displayDeleteOptions(): void {
|
||||||
|
// Hide all wrappers
|
||||||
|
this.hideAllWrappers();
|
||||||
|
|
||||||
|
this.populateExistingThemes("/_api/thememanager/GetTenantThemingOptions", {}).then((success: boolean) => {
|
||||||
|
if (success) {
|
||||||
|
// Display the dropdown.
|
||||||
|
document.getElementById(styles.themeSelectWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById('deleteTheme').classList.remove(styles.hide);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Display Apply Options:
|
||||||
|
This method is used to display the form elements for the Theme Apply Options.
|
||||||
|
***** *****/
|
||||||
|
public displayApplyOptions(): void {
|
||||||
|
// Hide all wrappers
|
||||||
|
this.hideAllWrappers();
|
||||||
|
|
||||||
|
// Display the dropdown.
|
||||||
|
document.getElementById(styles.themeNameWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById(styles.themePaletteWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById(styles.themeSiteURLWrapper).classList.remove(styles.hide);
|
||||||
|
document.getElementById('applyTheme').classList.remove(styles.hide);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Populate Existing Themes:
|
||||||
|
This method retrieves the currently available themes in the tenant and inserts the values into the dropdown.
|
||||||
|
***** *****/
|
||||||
|
public populateExistingThemes(url, params): Promise<boolean> {
|
||||||
|
|
||||||
|
|
||||||
|
return this.context.spHttpClient.get("/_api/thememanager/GetTenantThemingOptions", SPHttpClient.configurations.v1)
|
||||||
|
.then((response: SPHttpClientResponse) => {
|
||||||
|
return response.json();
|
||||||
|
}).then((themeJSON: any) => {
|
||||||
|
// Clear the select
|
||||||
|
let themeSelect = <HTMLInputElement>document.getElementById(styles.availableThemesSelect);
|
||||||
|
themeSelect.innerHTML = "";
|
||||||
|
|
||||||
|
for (let i = 0, max = themeJSON.themePreviews.length; i < max; i++) {
|
||||||
|
let option = document.createElement("option");
|
||||||
|
option.text = themeJSON.themePreviews[i].name;
|
||||||
|
(<HTMLInputElement>themeSelect).appendChild(option);
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Create new theme at tenant level:
|
||||||
|
Collects the data needed to create a new theme at the tenant level and passes it to the creation execution method.
|
||||||
|
***** *****/
|
||||||
|
public createTheme(): void {
|
||||||
|
|
||||||
|
// Gather the theme properties
|
||||||
|
let themeTitle: string = (<HTMLInputElement>document.getElementById(styles.input)).value;
|
||||||
|
let themePalette: JSON = JSON.parse((<HTMLInputElement>document.getElementById(styles.textarea)).value);
|
||||||
|
let themePaletteJSON = {
|
||||||
|
"palette": themePalette
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pass the theme properties to themeManagerExecution method
|
||||||
|
this.themeManagerExecution(this.context.pageContext.site.serverRelativeUrl + "/_api/thememanager/AddTenantTheme", { name: themeTitle, themeJson: JSON.stringify(themePaletteJSON) })
|
||||||
|
.then((sucess: boolean) => {
|
||||||
|
if (sucess) {
|
||||||
|
//it worked
|
||||||
|
alert('The theme has been successfully created');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//it didn't
|
||||||
|
alert('An error has occurred');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Deletes a theme at tenant level:
|
||||||
|
Collects the data needed to delete a theme at the tenant level and passes it to the deletion execution method.
|
||||||
|
***** *****/
|
||||||
|
public deleteTheme(): void {
|
||||||
|
|
||||||
|
// Gather the theme properties
|
||||||
|
let themeTitle: string = (<HTMLInputElement>document.getElementById(styles.availableThemesSelect)).value;
|
||||||
|
|
||||||
|
// Setup the success message
|
||||||
|
let successMessage: string = 'The theme has been successfully deleted';
|
||||||
|
|
||||||
|
// Pass the theme properties to themeManagerExecution method
|
||||||
|
this.themeManagerExecution(this.context.pageContext.site.serverRelativeUrl + "/_api/thememanager/DeleteTenantTheme", { name: themeTitle })
|
||||||
|
.then((sucess: boolean) => {
|
||||||
|
if (sucess) {
|
||||||
|
//it worked
|
||||||
|
alert('The theme has been successfully deleted');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//it didn't
|
||||||
|
alert('An error has occurred');
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Updates a theme at tenant level:
|
||||||
|
Collects the data needed to update a theme at the tenant level and passes it to the update execution method.
|
||||||
|
***** *****/
|
||||||
|
public updateTheme(): void {
|
||||||
|
|
||||||
|
// Gather the theme properties
|
||||||
|
let themeTitle: string = (<HTMLInputElement>document.getElementById(styles.availableThemesSelect)).value;
|
||||||
|
let themePalette: JSON = JSON.parse((<HTMLInputElement>document.getElementById(styles.textarea)).value);
|
||||||
|
let themePaletteJSON = {
|
||||||
|
"palette": themePalette
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pass the theme properties to themeManagerExecution method
|
||||||
|
this.themeManagerExecution(this.context.pageContext.site.serverRelativeUrl + "/_api/thememanager/UpdateTenantTheme", { name: themeTitle, themeJson: JSON.stringify(themePaletteJSON) })
|
||||||
|
.then((sucess: boolean) => {
|
||||||
|
if (sucess) {
|
||||||
|
//it worked
|
||||||
|
alert('The theme has been successfully updated');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//it didn't
|
||||||
|
alert('An error has occurred');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Apply a theme to a site collection:
|
||||||
|
Collects the data needed to apply a theme directly to a site colleciton.
|
||||||
|
NOTE: This does NOT create a theme choice at the tenant level. It will directly apply the theme to a site collection.
|
||||||
|
***** *****/
|
||||||
|
public applyThemeNew(): void {
|
||||||
|
|
||||||
|
// Gather the theme properties
|
||||||
|
let themeURL: string = (<HTMLInputElement>document.getElementById(styles.siteurl)).value;
|
||||||
|
let themeTitle: string = (<HTMLInputElement>document.getElementById(styles.input)).value;
|
||||||
|
let themePalette: JSON = JSON.parse((<HTMLInputElement>document.getElementById(styles.textarea)).value);
|
||||||
|
let themePaletteJSON = {
|
||||||
|
"palette": themePalette
|
||||||
|
}
|
||||||
|
|
||||||
|
const digestCache: IDigestCache = this.context.serviceScope.consume(DigestCache.serviceKey);
|
||||||
|
digestCache.fetchDigest(themeURL).then((digest: string): void => {
|
||||||
|
|
||||||
|
// Pass the theme properties to themeManagerExecution method
|
||||||
|
this.themeManagerExecution(themeURL + "/_api/thememanager/ApplyTheme", { name: themeTitle, themeJson: JSON.stringify(themePaletteJSON) })
|
||||||
|
.then((sucess: boolean) => {
|
||||||
|
if (sucess) {
|
||||||
|
//it worked
|
||||||
|
alert('The theme has been successfully applied');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//it didn't
|
||||||
|
alert('An error has occurred');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***** *****
|
||||||
|
Generic method for creating, updating, deleting and applying a theme.
|
||||||
|
***** *****/
|
||||||
|
public themeManagerExecution(url: string, params: any): Promise<boolean> {
|
||||||
|
|
||||||
|
let options: ISPHttpClientOptions = {
|
||||||
|
body: JSON.stringify(params)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.context.spHttpClient.post(url, SPHttpClient.configurations.v1, options)
|
||||||
|
.then((response: SPHttpClientResponse) => {
|
||||||
|
return response.ok
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse('1.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
description: strings.PropertyPaneDescription
|
||||||
|
},
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: strings.BasicGroupName,
|
||||||
|
groupFields: [
|
||||||
|
PropertyPaneTextField('description', {
|
||||||
|
label: strings.DescriptionFieldLabel
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "Description",
|
||||||
|
"BasicGroupName": "Group Name",
|
||||||
|
"DescriptionFieldLabel": "Description Field"
|
||||||
|
}
|
||||||
|
});
|
10
samples/js-theme-manager-2019/src/webparts/modernThemeManager/loc/mystrings.d.ts
vendored
Normal file
10
samples/js-theme-manager-2019/src/webparts/modernThemeManager/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
declare interface IModernThemeManagerWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
BasicGroupName: string;
|
||||||
|
DescriptionFieldLabel: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'ModernThemeManagerWebPartStrings' {
|
||||||
|
const strings: IModernThemeManagerWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@microsoft"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"es6-promise",
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es5",
|
||||||
|
"dom",
|
||||||
|
"es2015.collection"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -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