This commit is contained in:
Anders Mörtsell 2019-09-04 22:51:03 +02:00
commit 66628046a3
35 changed files with 20345 additions and 24 deletions

View File

@ -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

32
samples/js-myflows/.gitignore vendored Normal file
View File

@ -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

View File

@ -0,0 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"version": "1.8.2",
"libraryName": "myflows",
"libraryId": "80eca57a-37fc-4b0c-a893-3ff4c0e5b9ae",
"environment": "spo",
"packageManager": "npm",
"isCreatingSolution": true,
"isDomainIsolated": false,
"componentType": "webpart"
}
}

77
samples/js-myflows/README.md Executable file
View File

@ -0,0 +1,77 @@
# SPFx My Flows Web Part
## Summary
Manage current user flows in SharePoint or Teams Tab, this web part use the msflowsdk-1.1.js
##
![directory](/samples/js-myflows/assets/MyFlows.gif)
![directory](/samples/js-myflows/assets/Screenshot1.png)
![directory](/samples/js-myflows/assets/Screenshot2.png)
![directory](/samples/js-myflows/assets/Screenshot3.png)
![directory](/samples/js-myflows/assets/Screenshot4.png)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/version-1.8.2-green.svg)
## Applies to
* [SharePoint Online](https:/dev.office.com/sharepoint)
* [Microsoft Teams](https://products.office.com/en-US/microsoft-teams/group-chat-software)
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
## WebPart Properties
Property |Type|Required| comments
--------------------|----|--------|----------
Web Part Title | Text| no|
## Solution
The web part Use msflowsdk-1.1.js library
Solution|Author(s)
--------|---------
My FLows Web Part|João Mendes
## Version history
Version|Date|Comments
-------|----|--------
1.0.0|August 13, 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`
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/js-myflows" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"my-flows-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/myFlows/MyFlowsWebPart.js",
"manifest": "./src/webparts/myFlows/MyFlowsWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"MyFlowsWebPartStrings": "lib/webparts/myFlows/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -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": "myflows",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,14 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "myflows-client-side-solution",
"id": "80eca57a-37fc-4b0c-a893-3ff4c0e5b9ae",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/myflows.sppkg"
}
}

View File

@ -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/"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -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);

17406
samples/js-myflows/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
{
"name": "myflows",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.8.2",
"@microsoft/sp-property-pane": "1.8.2",
"@microsoft/sp-webpart-base": "1.8.2",
"@microsoft/sp-lodash-subset": "1.8.2",
"@microsoft/sp-office-ui-fabric-core": "1.8.2",
"@types/webpack-env": "1.13.1",
"@types/es6-promise": "0.0.33"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.8.2",
"@microsoft/sp-tslint-rules": "1.8.2",
"@microsoft/sp-module-interfaces": "1.8.2",
"@microsoft/sp-webpart-workbench": "1.8.2",
"@microsoft/rush-stack-compiler-2.9": "0.7.7",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}

View File

@ -0,0 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
import "./msflowsdk-1.1.js";
import {
SPHttpClient,
SPHttpClientResponse,
ISPHttpClientOptions
} from "@microsoft/sp-http";
import { WebPartContext } from "@microsoft/sp-webpart-base";
/**
* Services
*/
export default class services {
private _context: WebPartContext;
constructor(private context: WebPartContext) {
this._context = this.context;
}
/**
* Gets access token
* @returns access token
*/
public async getAccessToken():Promise<string> {
const body: ISPHttpClientOptions = {
body: JSON.stringify({
resource: "https://service.flow.microsoft.com/"
})
};
let token: SPHttpClientResponse = await this._context.spHttpClient.post(
`${this._context.pageContext.web.absoluteUrl}/_api/SP.OAuth.Token/Acquire`,
SPHttpClient.configurations.v1,
body
);
let tokenJson = await token.json();
return tokenJson.access_token;
}
}

View File

@ -0,0 +1,27 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "69105900-a016-43cb-9e28-9a16bb92cb87",
"alias": "MyFlowsWebPart",
"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,
"supportedHosts": ["SharePointWebPart","SharePointFullPage","TeamsTab"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "SPFx Apps" },
"title": { "default": "My Flows" },
"description": { "default": "My Flows" },
"officeFabricIconFontName": "MicrosoftFlowLogo",
"properties": {
"title": "My Flows"
}
}]
}

View File

@ -0,0 +1,42 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
iframe {
width:100%;
min-height: 800px;
padding: 10px;
overflow: hidden;
border-width: 0px;
border-style: solid;
border-color: $ms-color-white;
margin-top: 20px;
}
.label {
font-size: $ms-font-size-l;
height: 32px;
line-height: 32px;
margin: 0 4px;
vertical-align: top;
display: inline-block;
}
.sdk{
width:100%;
}
.titleTheme{
@include ms-font-xl;
@include ms-fontSize-24;
}
.titleWhite{
@include ms-font-xl;
@include ms-fontSize-24;
color: white;
}
.error{
@include ms-font-xl;
@include ms-fontSize-24;
color: red;
margin: 15px;
}

View File

@ -0,0 +1,148 @@
import { Version, Guid } from "@microsoft/sp-core-library";
import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from "@microsoft/sp-property-pane";
import { escape } from "@microsoft/sp-lodash-subset";
import styles from "./MyFlowsWebPart.module.scss";
import * as strings from "MyFlowsWebPartStrings";
import service from "./../../services/services";
export interface IMyFlowsWebPartProps {
title: string;
}
export default class MyFlowsWebPart extends BaseClientSideWebPart<
IMyFlowsWebPartProps
> {
private _msFlowSdk: any = null;
private _services: service = null;
private _guid = Guid.newGuid();
public constructor(props: IMyFlowsWebPartProps) {
super();
// Initialize flow SDK
this._msFlowSdk = window["MsFlowSdk"];
}
/**
* Gets context
* @returns context
*/
private getContext(): Promise<string> {
return new Promise((resolve, reject) => {
let classColor = styles.titleTheme;
if (this.context.microsoftTeams) {
this.context.microsoftTeams.getContext(teamsContext => {
classColor =
teamsContext.theme !== "default"
? styles.titleWhite
: styles.titleTheme;
resolve(classColor);
});
} else {
resolve(classColor);
}
});
}
/**
* Renders my flows web part
*/
public async render(): Promise<void> {
this.domElement.setAttribute("Id", `"${this._guid}"`);
this.domElement.setAttribute("class", `"${styles.sdk}"`);
const classColor = await this.getContext();
this.domElement.innerHTML = `<div><label class=${classColor}>${
this.properties.title
}</label></div>`;
//
this._services = new service(this.context);
try {
const token: string = await this._services.getAccessToken();
const flowSDK = new this._msFlowSdk({
hostName: "https://flow.microsoft.com",
locale: this.context.pageContext.cultureInfo.currentCultureName
});
// Render Flow widget
let widget: any = flowSDK.renderWidget("flows", {
container: `"${this._guid}"`,
sdkVersion: "1.1",
enableOnBehalfOfTokens: true,
debugMode: false,
allowOptionalEvents: true,
flowsSettings: {
createFromBlankTemplateId: "05ed784f63df4ac7b8cbb465005d6068",
encodedFlowsFilter: "",
isMini: false,
enableBusinessProcessFlow: true
},
templatesSettings: {
defaultParams: "",
category: "PowerAppsButton",
destination: "new",
metadataSortProperty: "",
pageSize: 6,
searchTerm: "",
useServerSideProvisioning: false,
showGoBack: true,
enableWidgetCloseOnFlowSave: false,
showCreateFromBlank: false,
enableDietDesigner: false,
showHiddenTemplates: false,
allowCustomFlowName: false,
oneClickCategory: "",
dietCategory: ""
},
widgetStyleSettings: {
backgroundColor: "",
themeName: ""
}
});
// Register handler
widget.listen("GET_ACCESS_TOKEN", (requestParam, widgetDoneCallback) => {
widgetDoneCallback(null, { token: token });
});
// Register handler
widget.listen("WIDGET_READY", () => {
console.log("The flow widget is now ready.");
});
} catch (error) {
// error
this.domElement.innerHTML = `<div><label class=${classColor}>${
this.properties.title
}</label></div>
<div ><label class=${styles.error}>${error}</label></div>
`;
}
}
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.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Manage My Flows in SharePoint ",
"BasicGroupName": "Properties",
"DescriptionFieldLabel": "Title"
}
});

View File

@ -0,0 +1,10 @@
declare interface IMyFlowsWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'MyFlowsWebPartStrings' {
const strings: IMyFlowsWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,38 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-2.9/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noUnusedLocals": false,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -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
}
}

View File

@ -0,0 +1,6 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}

View File

@ -2,6 +2,7 @@ import { WebPartContext } from "@microsoft/sp-webpart-base";
import { graph } from "@pnp/graph"; import { graph } from "@pnp/graph";
import { sp, PeoplePickerEntity, ClientPeoplePickerQueryParameters, SearchQuery, SearchResults, SearchProperty, SortDirection } from '@pnp/sp'; import { sp, PeoplePickerEntity, ClientPeoplePickerQueryParameters, SearchQuery, SearchResults, SearchProperty, SortDirection } from '@pnp/sp';
import { PrincipalType } from "@pnp/sp/src/sitegroups"; import { PrincipalType } from "@pnp/sp/src/sitegroups";
import { isRelativeUrl } from "office-ui-fabric-react";
export class spservices { export class spservices {
@ -67,6 +68,9 @@ user:string */
SortList: [{ "Property": "LastName", "Direction": SortDirection.Ascending }], SortList: [{ "Property": "LastName", "Direction": SortDirection.Ascending }],
}); });
return users; return users;
} catch (error) { } catch (error) {
Promise.reject(error); Promise.reject(error);

View File

@ -99,6 +99,33 @@ export default class Directory extends React.Component<
await this._searchUsers("A"); await this._searchUsers("A");
} }
/**
* Gets image base64
* @param pictureUrl
* @returns
*/
private getImageBase64(pictureUrl: string):Promise<string>{
return new Promise((resolve, reject) => {
let image = new Image();
image.addEventListener("load", () => {
let tempCanvas = document.createElement("canvas");
tempCanvas.width = image.width,
tempCanvas.height = image.height,
tempCanvas.getContext("2d").drawImage(image, 0, 0);
let base64Str;
try {
base64Str = tempCanvas.toDataURL("image/png");
} catch (e) {
return "";
}
resolve(base64Str);
});
image.src = pictureUrl;
});
}
private async _searchUsers(searchText: string) { private async _searchUsers(searchText: string) {
searchText = searchText.trim().length > 0 ? searchText : "A"; searchText = searchText.trim().length > 0 ? searchText : "A";
this.setState({ this.setState({
@ -112,6 +139,17 @@ export default class Directory extends React.Component<
searchText, searchText,
this.props.searchFirstName this.props.searchFirstName
); );
if (users && users.PrimarySearchResults.length > 0){
for (let index = 0; index < users.PrimarySearchResults.length; index++) {
let user:any = users.PrimarySearchResults[index] ;
if (user.PictureURL){
user = { ...user, PictureURL: await this.getImageBase64(`/_layouts/15/userphoto.aspx?size=M&accountname=${user.WorkEmail}`)};
users.PrimarySearchResults[index] = user ;
}
}
}
this.setState({ this.setState({
users: users:
users && users.PrimarySearchResults users && users.PrimarySearchResults

View File

@ -1,16 +1,16 @@
import * as React from "react"; import * as React from 'react';
import styles from "./PersonaCard.module.scss"; import styles from './PersonaCard.module.scss';
import { IPersonaCardProps } from "./IPersonaCardProps"; import { IPersonaCardProps } from './IPersonaCardProps';
import { IPersonaCardState } from "./IPersonaCardState"; import { IPersonaCardState } from './IPersonaCardState';
import { import {
Version, Version,
Environment, Environment,
EnvironmentType, EnvironmentType,
ServiceScope, ServiceScope,
Log, Log,
Text Text,
} from "@microsoft/sp-core-library"; } from '@microsoft/sp-core-library';
import { SPComponentLoader } from "@microsoft/sp-loader"; import { SPComponentLoader } from '@microsoft/sp-loader';
import { import {
Persona, Persona,
@ -22,13 +22,12 @@ import {
DocumentCard, DocumentCard,
IDocumentCardStyles, IDocumentCardStyles,
DocumentCardType, DocumentCardType,
Icon Icon,
} from "office-ui-fabric-react"; } from 'office-ui-fabric-react';
const EXP_SOURCE: string = "SPFxDirectory"; const EXP_SOURCE: string = 'SPFxDirectory';
const LIVE_PERSONA_COMPONENT_ID: string = const LIVE_PERSONA_COMPONENT_ID: string =
"914330ee-2df2-4f6e-a858-30c23a812408"; '914330ee-2df2-4f6e-a858-30c23a812408';
//const PROFILE_IMAGE_URL: string = 'https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email={0}&UA=0&size=HR96x96&sc=1564597822258';
export class PersonaCard extends React.Component< export class PersonaCard extends React.Component<
IPersonaCardProps, IPersonaCardProps,
@ -36,6 +35,7 @@ export class PersonaCard extends React.Component<
> { > {
constructor(props: IPersonaCardProps) { constructor(props: IPersonaCardProps) {
super(props); super(props);
this.state = { livePersonaCard: undefined, pictureUrl: undefined }; this.state = { livePersonaCard: undefined, pictureUrl: undefined };
} }
/** /**
@ -78,11 +78,11 @@ export class PersonaCard extends React.Component<
serviceScope: this.props.context.serviceScope, serviceScope: this.props.context.serviceScope,
upn: this.props.profileProperties.Email, upn: this.props.profileProperties.Email,
onCardOpen: () => { onCardOpen: () => {
console.log("LivePersonaCard Open"); console.log('LivePersonaCard Open');
}, },
onCardClose: () => { onCardClose: () => {
console.log("LivePersonaCard Close"); console.log('LivePersonaCard Close');
} },
}, },
this._PersonaCard() this._PersonaCard()
); );
@ -113,25 +113,25 @@ export class PersonaCard extends React.Component<
> >
{this.props.profileProperties.WorkPhone ? ( {this.props.profileProperties.WorkPhone ? (
<div> <div>
<Icon iconName="Phone" style={{ fontSize: "12px" }} /> <Icon iconName="Phone" style={{ fontSize: '12px' }} />
<span style={{ marginLeft: 5, fontSize: "12px" }}> <span style={{ marginLeft: 5, fontSize: '12px' }}>
{" "} {' '}
{this.props.profileProperties.WorkPhone} {this.props.profileProperties.WorkPhone}
</span> </span>
</div> </div>
) : ( ) : (
"" ''
)} )}
{this.props.profileProperties.Location ? ( {this.props.profileProperties.Location ? (
<div> <div>
<Icon iconName="Poi" style={{ fontSize: "12px" }} /> <Icon iconName="Poi" style={{ fontSize: '12px' }} />
<span style={{ marginLeft: 5, fontSize: "12px" }}> <span style={{ marginLeft: 5, fontSize: '12px' }}>
{" "} {' '}
{this.props.profileProperties.Location} {this.props.profileProperties.Location}
</span> </span>
</div> </div>
) : ( ) : (
"" ''
)} )}
</Persona> </Persona>
</div> </div>

View File

@ -6,7 +6,21 @@
"version": "1.0.0.0", "version": "1.0.0.0",
"includeClientSideAssets": true, "includeClientSideAssets": true,
"skipFeatureDeployment": true, "skipFeatureDeployment": true,
"isDomainIsolated": false "isDomainIsolated": false,
"webApiPermissionRequests": [
{
"resource": "Microsoft Graph",
"scope": "User.Read.All"
},
{
"resource": "Microsoft Graph",
"scope": "Directory.Read.All"
},
{
"resource": "Microsoft Graph",
"scope": "Directory.AccessAsUser.All"
}
]
}, },
"paths": { "paths": {
"zippedPackage": "solution/react-manage-sitedesigns.sppkg" "zippedPackage": "solution/react-manage-sitedesigns.sppkg"