Initial commit of Save Email to SharePoint outlook add in
This commit is contained in:
parent
27cd1f666e
commit
fac9d2b87b
|
@ -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,12 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"version": "1.10.0",
|
||||
"libraryName": "save-email-to-sharepoint",
|
||||
"libraryId": "a1464bb8-773a-438c-a425-b5fc2a5a86a4",
|
||||
"environment": "spo",
|
||||
"packageManager": "npm",
|
||||
"isCreatingSolution": true,
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
## save-email-to-sharepoint
|
||||
|
||||
This is where you include your WebPart documentation.
|
||||
|
||||
### Building the code
|
||||
|
||||
```bash
|
||||
git clone the repo
|
||||
npm i
|
||||
npm i -g gulp
|
||||
gulp
|
||||
```
|
||||
|
||||
This package produces the following:
|
||||
|
||||
* lib/* - intermediate-stage commonjs build artifacts
|
||||
* dist/* - the bundled script, along with other resources
|
||||
* deploy/* - all resources which should be uploaded to a CDN.
|
||||
|
||||
### Build options
|
||||
|
||||
gulp clean - TODO
|
||||
gulp test - TODO
|
||||
gulp serve - TODO
|
||||
gulp bundle - TODO
|
||||
gulp package-solution - TODO
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"save-email-to-share-point-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/saveEmailToSharePoint/SaveEmailToSharePointWebPart.js",
|
||||
"manifest": "./src/webparts/saveEmailToSharePoint/SaveEmailToSharePointWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"SaveEmailToSharePointWebPartStrings": "lib/webparts/saveEmailToSharePoint/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": "save-email-to-sharepoint",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "save-email-to-sharepoint-client-side-solution",
|
||||
"id": "a1464bb8-773a-438c-a425-b5fc2a5a86a4",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false,
|
||||
"webApiPermissionRequests": [
|
||||
{
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Mail.ReadBasic"
|
||||
},
|
||||
{
|
||||
"resource": "Microsoft Graph",
|
||||
"scope": "Mail.Read"
|
||||
}
|
||||
]
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/save-email-to-sharepoint.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 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(require('gulp'));
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
|
||||
xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0"
|
||||
xsi:type="MailApp">
|
||||
<Id>e6083c02-3280-4430-a877-22cbc6251d21</Id>
|
||||
<Version>1.0.0.0</Version>
|
||||
<ProviderName>Save Email Provider</ProviderName>
|
||||
<DefaultLocale>en-US</DefaultLocale>
|
||||
<DisplayName DefaultValue="Save Email to SharePoint"/>
|
||||
<Description DefaultValue="A template to get started with a Save Email as file in SharePoint Outlook addin."/>
|
||||
<IconUrl DefaultValue="https://spoprod-a.akamaihd.net/files/fabric/assets/item-types/32_1.5x/email.png"/>
|
||||
<HighResolutionIconUrl DefaultValue="https://cdn.graph.office.net/prod/media/shared/addin-icon.png"/>
|
||||
<SupportUrl DefaultValue="https://localhost:4321/help"/>
|
||||
<AppDomains>
|
||||
<AppDomain>https://login.microsoftonline.com</AppDomain>
|
||||
<AppDomain>https://login.windows.net</AppDomain>
|
||||
</AppDomains>
|
||||
<Hosts>
|
||||
<Host Name="Mailbox" />
|
||||
</Hosts>
|
||||
<Requirements>
|
||||
<Sets>
|
||||
<Set Name="Mailbox" MinVersion="1.4" />
|
||||
<Set Name="SharePointHostedAddin" MinVersion="1.1" />
|
||||
</Sets>
|
||||
</Requirements>
|
||||
<FormSettings>
|
||||
<Form xsi:type="ItemRead">
|
||||
<DesktopSettings>
|
||||
<SourceLocation DefaultValue="https://_SharePointTenantUrl_/_layouts/15/outlookhostedapp.aspx?componentId=e6083c02-3280-4430-a877-22cbc6251d21&isConfigureMode=true"/>
|
||||
<RequestedHeight>250</RequestedHeight>
|
||||
</DesktopSettings>
|
||||
</Form>
|
||||
</FormSettings>
|
||||
<Permissions>ReadWriteMailbox</Permissions>
|
||||
<Rule xsi:type="RuleCollection" Mode="Or">
|
||||
<Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
|
||||
</Rule>
|
||||
<DisableEntityHighlighting>false</DisableEntityHighlighting>
|
||||
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
|
||||
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
|
||||
<Hosts>
|
||||
<Host xsi:type="MailHost">
|
||||
<DesktopFormFactor>
|
||||
<ExtensionPoint xsi:type="MessageReadCommandSurface">
|
||||
<OfficeTab id="TabDefault">
|
||||
<Group id="msgReadGroup">
|
||||
<Label resid="GroupLabel" />
|
||||
<Control xsi:type="Button" id="msgReadOpenPaneButton">
|
||||
<Label resid="TaskpaneButton.Label" />
|
||||
<Supertip>
|
||||
<Title resid="TaskpaneButton.Label" />
|
||||
<Description resid="TaskpaneButton.Tooltip" />
|
||||
</Supertip>
|
||||
<Icon>
|
||||
<bt:Image size="16" resid="Icon.16x16" />
|
||||
<bt:Image size="32" resid="Icon.32x32" />
|
||||
<bt:Image size="80" resid="Icon.80x80" />
|
||||
</Icon>
|
||||
<Action xsi:type="ShowTaskpane">
|
||||
<SourceLocation resid="Taskpane.Url" />
|
||||
</Action>
|
||||
</Control>
|
||||
</Group>
|
||||
</OfficeTab>
|
||||
</ExtensionPoint>
|
||||
</DesktopFormFactor>
|
||||
</Host>
|
||||
</Hosts>
|
||||
<Resources>
|
||||
<bt:Images>
|
||||
<bt:Image id="Icon.16x16" DefaultValue="https://cdn.graph.office.net/prod/media/shared/addin-icon.png"/>
|
||||
<bt:Image id="Icon.32x32" DefaultValue="https://cdn.graph.office.net/prod/media/shared/addin-icon.png"/>
|
||||
<bt:Image id="Icon.80x80" DefaultValue="https://cdn.graph.office.net/prod/media/shared/addin-icon.png"/>
|
||||
</bt:Images>
|
||||
<bt:Urls>
|
||||
<bt:Url id="Taskpane.Url" DefaultValue="https://_SharePointTenantUrl_/_layouts/15/outlookhostedapp.aspx?componentId=e6083c02-3280-4430-a877-22cbc6251d21&isConfigureMode=true" />
|
||||
</bt:Urls>
|
||||
<bt:ShortStrings>
|
||||
<bt:String id="GroupLabel" DefaultValue="Add-in groupLabel"/>
|
||||
<bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
|
||||
</bt:ShortStrings>
|
||||
<bt:LongStrings>
|
||||
<bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens taskpane."/>
|
||||
</bt:LongStrings>
|
||||
</Resources>
|
||||
</VersionOverrides>
|
||||
</VersionOverrides>
|
||||
</OfficeApp>
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"name": "save-email-to-sharepoint",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-lodash-subset": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-property-pane": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-webpart-base": "1.10.0-plusbeta",
|
||||
"@pnp/sp": "^2.0.4",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/office-js": "^1.0.97",
|
||||
"@types/react": "16.8.8",
|
||||
"@types/react-dom": "16.8.3",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"office-ui-fabric-react": "6.189.2",
|
||||
"react": "16.8.5",
|
||||
"react-dom": "16.8.5"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/react": "16.8.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/sp-build-web": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-tslint-rules": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-module-interfaces": "1.10.0-plusbeta",
|
||||
"@microsoft/sp-webpart-workbench": "1.10.0-plusbeta",
|
||||
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
|
||||
"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,27 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "e6083c02-3280-4430-a877-22cbc6251d21",
|
||||
"alias": "SaveEmailToSharePointWebPart",
|
||||
"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"],
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "SaveEmailToSharePoint" },
|
||||
"description": { "default": "Save your Email to sharepoint from the outlook add-in web" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"description": "SaveEmailToSharePoint"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
IPropertyPaneConfiguration,
|
||||
PropertyPaneTextField
|
||||
} from '@microsoft/sp-property-pane';
|
||||
import { BaseClientSideWebPart, WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { sp } from "@pnp/sp/presets/all";
|
||||
import * as strings from 'SaveEmailToSharePointWebPartStrings';
|
||||
import SaveEmailToSharePoint from './components/SaveEmailToSharePoint';
|
||||
import { ISaveEmailToSharePointProps } from './components/ISaveEmailToSharePointProps';
|
||||
|
||||
export interface ISaveEmailToSharePointWebPartProps {
|
||||
description: string;
|
||||
context: WebPartContext;
|
||||
}
|
||||
|
||||
export default class SaveEmailToSharePointWebPart extends BaseClientSideWebPart <ISaveEmailToSharePointWebPartProps> {
|
||||
protected onInit(): Promise<void> {
|
||||
return super.onInit().then(_ => {
|
||||
sp.setup({
|
||||
spfxContext: this.context
|
||||
});
|
||||
});
|
||||
}
|
||||
public render(): void {
|
||||
const element: React.ReactElement<ISaveEmailToSharePointProps> = React.createElement(
|
||||
SaveEmailToSharePoint,
|
||||
{
|
||||
description: this.properties.description,
|
||||
context: this.context
|
||||
}
|
||||
);
|
||||
|
||||
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: [
|
||||
{
|
||||
groups: [
|
||||
{
|
||||
groupFields: [
|
||||
PropertyPaneTextField('description', {
|
||||
label: strings.DescriptionFieldLabel
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||
|
||||
export interface ISaveEmailToSharePointProps {
|
||||
description: string;
|
||||
context: WebPartContext;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
import {SPRest} from '@pnp/sp';
|
||||
import "@pnp/sp/webs";
|
||||
import "@pnp/sp/items/list";
|
||||
import "@pnp/sp/lists";
|
||||
import "@pnp/sp/sites";
|
||||
import "@pnp/sp/search";
|
||||
export const sp= new SPRest();
|
|
@ -0,0 +1,84 @@
|
|||
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||
|
||||
.saveEmailToSharePoint {
|
||||
.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 {
|
||||
@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;
|
||||
}
|
||||
|
||||
.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;
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:global {
|
||||
.btnSave {
|
||||
margin-top: 5px;
|
||||
}
|
||||
.btnCancel{
|
||||
margin-top: 5px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,166 @@
|
|||
import * as React from 'react';
|
||||
import styles from './SaveEmailToSharePoint.module.scss';
|
||||
import { ISaveEmailToSharePointProps } from './ISaveEmailToSharePointProps';
|
||||
import { SearchResults } from "@pnp/sp/search";
|
||||
import { Icon, Dropdown, IDropdownOption, IDropdownStyles, PrimaryButton, Label, IDropdownProps, Link } from 'office-ui-fabric-react';
|
||||
import Services from './Services/Services';
|
||||
import * as strings from 'SaveEmailToSharePointWebPartStrings';
|
||||
|
||||
|
||||
const dropdownStyles: Partial<IDropdownStyles> = { dropdown: { width: 300 } };
|
||||
interface SaveEmailToSharePointState {
|
||||
allSites: any;
|
||||
selectedSite: any;
|
||||
allLibraries: any;
|
||||
selectedLibrary: any;
|
||||
savedLink: string;
|
||||
rootURL: string;
|
||||
}
|
||||
export default class SaveEmailToSharePoint extends React.Component<ISaveEmailToSharePointProps, SaveEmailToSharePointState> {
|
||||
private services = new Services();
|
||||
constructor(props: ISaveEmailToSharePointProps, state: SaveEmailToSharePointState) {
|
||||
super(props);
|
||||
this.state = {
|
||||
allSites: null,
|
||||
selectedSite: null,
|
||||
allLibraries: null,
|
||||
selectedLibrary: null,
|
||||
savedLink: '',
|
||||
rootURL: ''
|
||||
}
|
||||
}
|
||||
public componentWillMount() {
|
||||
this.getAllSites();
|
||||
this.getRootURL();
|
||||
}
|
||||
|
||||
public getRootURL = () => {
|
||||
this.services.getRootSiteURL().then((rootURL) => {
|
||||
this.setState({
|
||||
rootURL: rootURL
|
||||
});
|
||||
});
|
||||
}
|
||||
private saveToLibrary = (file) => {
|
||||
let filename = Office.context.mailbox.item.subject + ".eml";
|
||||
this.services.saveFileToSP(this.state.selectedSite.key, this.state.selectedLibrary.key, filename, file).then((result) => {
|
||||
console.log(result.data.ServerRelativeUrl);
|
||||
this.setState({
|
||||
savedLink: this.state.rootURL + result.data.ServerRelativeUrl + "?web=1"
|
||||
})
|
||||
});
|
||||
}
|
||||
public getAllSites = () => {
|
||||
this.services.getSiteNames().then((allSiteResults: SearchResults) => {
|
||||
console.log(allSiteResults.PrimarySearchResults);
|
||||
let allsite = [];
|
||||
allSiteResults.PrimarySearchResults.forEach(element => {
|
||||
let siteValue = { key: element.Path, text: element.Title };
|
||||
allsite.push(siteValue);
|
||||
});
|
||||
this.setState({
|
||||
allSites: allsite
|
||||
});
|
||||
});
|
||||
}
|
||||
public getCurrentEmailContent = () => {
|
||||
let id = Office.context.mailbox.item.itemId;
|
||||
this.services.getEmailContent(this.props.context, id).then((response: any) => {
|
||||
console.log(response);
|
||||
//save to library
|
||||
this.saveToLibrary(response);
|
||||
}).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
public OnSelectSite = (event: React.FormEvent<HTMLDivElement>, item: IDropdownOption) => {
|
||||
this.services.getAllDocumentLibary(item.key.toString()).then((libraries) => {
|
||||
if (libraries.length) {
|
||||
let allLib = [];
|
||||
libraries.forEach(element => {
|
||||
let library = { key: element.ServerRelativeUrl, text: element.Title };
|
||||
allLib.push(library);
|
||||
});
|
||||
this.setState({
|
||||
selectedSite: item,
|
||||
allLibraries: allLib
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
selectedSite: item
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
public OnSelectLibrary = (event: React.FormEvent<HTMLDivElement>, item: IDropdownOption) => {
|
||||
this.setState({
|
||||
selectedLibrary: item
|
||||
});
|
||||
}
|
||||
public render(): React.ReactElement<ISaveEmailToSharePointProps> {
|
||||
return (
|
||||
<div className="ms-Grid" >
|
||||
<div className={styles.row}>
|
||||
{this.state.allSites ? <Dropdown
|
||||
label={strings.SiteLabel}
|
||||
selectedKey={this.state.selectedSite ? this.state.selectedSite.key : undefined}
|
||||
onChange={this.OnSelectSite}
|
||||
placeholder={strings.SitePlaceHolder}
|
||||
options={this.state.allSites}
|
||||
styles={dropdownStyles}
|
||||
className={styles.column}
|
||||
onRenderPlaceholder={this.onRenderforSite}
|
||||
/> : null}
|
||||
</div>
|
||||
<div className={styles.row}>
|
||||
{this.state.allLibraries ? <Dropdown
|
||||
label={strings.LibraryLabel}
|
||||
selectedKey={this.state.selectedLibrary ? this.state.selectedLibrary.key : undefined}
|
||||
onChange={this.OnSelectLibrary}
|
||||
placeholder={strings.LibraryPlaceHolder}
|
||||
options={this.state.allLibraries}
|
||||
styles={dropdownStyles}
|
||||
className={styles.column + " ms-fadeIn200"}
|
||||
onRenderPlaceholder={this.onRenderforLib}
|
||||
/> : null}
|
||||
</div>
|
||||
<div className={styles.row}>
|
||||
<PrimaryButton
|
||||
text={strings.Save}
|
||||
disabled={this.state.selectedLibrary ? false : true}
|
||||
className={styles.column + " btnSave"}
|
||||
onClick={this.getCurrentEmailContent} />
|
||||
|
||||
<PrimaryButton
|
||||
text={strings.Cancel}
|
||||
className={styles.column + " btnCancel"}
|
||||
onClick={() => { Office.context.ui.closeContainer(); }} />
|
||||
</div>
|
||||
<div className={styles.row}>
|
||||
{this.state.savedLink.length ?
|
||||
<Link href={this.state.savedLink} target='_blank' className="ms-fadeIn500">
|
||||
Click to view the saved email
|
||||
</Link>
|
||||
: null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
public onRenderforLib = (props: IDropdownProps): JSX.Element => {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Icon iconName="DocLibrary" className="ms-Grid-col ms-u-sm1" />
|
||||
<Label className="ms-Grid-col ms-u-sm4" style={{ marginTop: -4 }}>{props.label}</Label>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
public onRenderforSite = (props: IDropdownProps): JSX.Element => {
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Icon iconName="Website" className="ms-Grid-col ms-u-sm1" />
|
||||
<Label className="ms-Grid-col ms-u-sm4" style={{ marginTop: -4 }}>{props.label}</Label>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import { sp } from '../SPPreset';
|
||||
import { Web } from '@pnp/sp/webs';
|
||||
import { SearchResults } from '@pnp/sp/search';
|
||||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
import { MSGraphClient } from "@microsoft/sp-http";
|
||||
|
||||
export default class Services {
|
||||
public async getSiteNames(): Promise<SearchResults> {
|
||||
const allSiteResults: SearchResults = await sp.search({
|
||||
Querytext: "contentclass:STS_Site contentclass:STS_Web",
|
||||
EnableInterleaving: true,
|
||||
RowLimit: 100
|
||||
});
|
||||
return allSiteResults;
|
||||
}
|
||||
public getRootSiteURL(): Promise<string> {
|
||||
return sp.web.get().then((data) => {
|
||||
return data.ResourcePath.DecodedUrl;
|
||||
});
|
||||
}
|
||||
public saveFileToSP(SiteURL: string, serverRelativeURL: string, filename: string, file): Promise<any> {
|
||||
let web = Web(SiteURL);
|
||||
return web.getFolderByServerRelativeUrl(serverRelativeURL).files.add(filename, file, true).then((result) => {
|
||||
return result;
|
||||
});
|
||||
}
|
||||
public getEmailContent(context: WebPartContext, id: string): Promise<any> {
|
||||
return context.msGraphClientFactory.getClient().then((client: MSGraphClient): void => {
|
||||
client.api('/me/messages/' + id + '/$value').version('v1.0').responseType('blob').get().then((response: any) => {
|
||||
return response;
|
||||
});
|
||||
});
|
||||
}
|
||||
public getAllDocumentLibary(absoluteURL: string): Promise<any[]> {
|
||||
return sp.site.getDocumentLibraries(absoluteURL).then((libraries: any[]) => {
|
||||
return libraries;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 527 B |
|
@ -0,0 +1,13 @@
|
|||
define([], function () {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field",
|
||||
"SiteLabel": "Select a site",
|
||||
"SitePlaceHolder": "Select a site",
|
||||
"LibraryLabel": "Select a Library",
|
||||
"LibraryPlaceHolder": "Select a Library",
|
||||
"Save": "Save",
|
||||
"Cancel": "Cancel"
|
||||
}
|
||||
});
|
|
@ -0,0 +1,16 @@
|
|||
declare interface ISaveEmailToSharePointWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
SiteLabel:string;
|
||||
SitePlaceHolder: string;
|
||||
LibraryLabel: string;
|
||||
LibraryPlaceHolder: string;
|
||||
Save: string;
|
||||
Cancel: string;
|
||||
}
|
||||
|
||||
declare module 'SaveEmailToSharePointWebPartStrings' {
|
||||
const strings: ISaveEmailToSharePointWebPartStrings;
|
||||
export = strings;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/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"
|
||||
]
|
||||
}
|
|
@ -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