Skip to content

Commit

Permalink
Merge pull request #24 from DariuS231/favourites
Browse files Browse the repository at this point in the history
Favourites
  • Loading branch information
DariuS231 authored Oct 9, 2017
2 parents 88f18c9 + 7b8047f commit 13b0715
Show file tree
Hide file tree
Showing 42 changed files with 537 additions and 316 deletions.
11 changes: 1 addition & 10 deletions dist/actions/SpPropertyBag/SpPropertyBag.js

Large diffs are not rendered by default.

13 changes: 1 addition & 12 deletions dist/actions/SpSiteContent/SpSiteContent.js

Large diffs are not rendered by default.

11 changes: 1 addition & 10 deletions dist/actions/spFeatures/spFeatures.js

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions dist/actions/spSiteCustomActions/spSiteCustomActions.js

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions dist/actions/spWebCustomActions/spWebCustomActions.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/actions/styles/bundle.css

Large diffs are not rendered by default.

149 changes: 75 additions & 74 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,75 +1,76 @@
{
"name": "chromesppropertiesadmin",
"version": "0.0.1",
"description": "Google Chrome extension that opens a Property bag Modal dialog administration",
"scripts": {
"start": "set NODE_ENV=development && node server.js",
"bundleActions": "set NODE_ENV=production && webpack --progress --config ./webpack/webpack.config.actions.prod.js",
"bundleChromeExtension": "set NODE_ENV=production && gulp build-chromeExt",
"generate": "set NODE_ENV=production && gulp generate-chrome-dev",
"generateZip": "set NODE_ENV=production && gulp generate-chrome-package"
},
"dependencies": {
"axios": "^0.15.3",
"office-ui-fabric-react": "^1.5.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^3.0.2",
"redux-thunk": "^2.1.0"
},
"devDependencies": {
"@types/axios": "^0.9.35",
"@types/chrome": "0.0.35",
"@types/core-js": "^0.9.34",
"@types/microsoft-ajax": "0.0.31",
"@types/react": "^0.14.46",
"@types/react-dom": "^0.14.18",
"@types/react-redux": "^4.4.35",
"@types/react-router": "2.0.29",
"@types/redux-immutable-state-invariant": "^1.2.29",
"@types/redux-thunk": "^2.1.32",
"@types/sharepoint": "^2013.1.2",
"awesome-typescript-loader": "^3.0.0-beta.18",
"css-loader": "^0.26.1",
"es6-promise": "4.0.5",
"extract-text-webpack-plugin": "^2.0.0-rc.2",
"gulp": "^3.9.1",
"gulp-util": "^3.0.8",
"gulp-zip": "^3.2.0",
"http-server": "^0.9.0",
"immutable": "^3.8.1",
"node-sass": "^4.4.0",
"opener": "^1.4.2",
"path": "^0.12.7",
"react-redux": "^5.0.1",
"redux": "^3.6.0",
"redux-immutable-state-invariant": "^1.2.4",
"sass-loader": "^4.1.1",
"source-map-loader": "^0.1.6",
"style-loader": "^0.13.1",
"tslint": "^4.4.2",
"tslint-react": "^2.3.0",
"typescript": "2.3.4",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.2.1",
"whatwg-fetch": "1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/DariuS231/ChromeSPPropertiesAdmin.git"
},
"keywords": [
"SharePoint",
"PropertyBag",
"CSOM",
"JavaScript",
"Google Chrome",
"Chrome Extension"
],
"author": "Darius231",
"license": "MIT",
"bugs": {
"url": "https://github.com/DariuS231/ChromeSPPropertiesAdmin/issues"
},
"homepage": "https://github.com/DariuS231/ChromeSPPropertiesAdmin#readme"
}
"name": "chromesppropertiesadmin",
"version": "0.0.1",
"description": "Google Chrome extension that opens a Property bag Modal dialog administration",
"scripts": {
"start": "set NODE_ENV=development && node server.js",
"bundleActions": "set NODE_ENV=production && webpack --progress --config ./webpack/webpack.config.actions.prod.js",
"bundleChromeExtension": "set NODE_ENV=production && gulp build-chromeExt",
"generate": "set NODE_ENV=production && gulp generate-chrome-dev",
"generateZip": "set NODE_ENV=production && gulp generate-chrome-package"
},
"dependencies": {
"axios": "^0.15.3",
"office-ui-fabric-react": "^1.5.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^3.0.2",
"redux-thunk": "^2.1.0",
"sp-pnp-js": "^3.0.1"
},
"devDependencies": {
"@types/axios": "^0.9.35",
"@types/chrome": "0.0.35",
"@types/core-js": "^0.9.34",
"@types/microsoft-ajax": "0.0.31",
"@types/react": "^0.14.46",
"@types/react-dom": "^0.14.18",
"@types/react-redux": "^4.4.35",
"@types/react-router": "2.0.29",
"@types/redux-immutable-state-invariant": "^1.2.29",
"@types/redux-thunk": "^2.1.32",
"@types/sharepoint": "^2013.1.2",
"awesome-typescript-loader": "^3.0.0-beta.18",
"css-loader": "^0.26.1",
"es6-promise": "4.0.5",
"extract-text-webpack-plugin": "^2.0.0-rc.2",
"gulp": "^3.9.1",
"gulp-util": "^3.0.8",
"gulp-zip": "^3.2.0",
"http-server": "^0.9.0",
"immutable": "^3.8.1",
"node-sass": "^4.4.0",
"opener": "^1.4.2",
"path": "^0.12.7",
"react-redux": "^5.0.1",
"redux": "^3.6.0",
"redux-immutable-state-invariant": "^1.2.4",
"sass-loader": "^4.1.1",
"source-map-loader": "^0.1.6",
"style-loader": "^0.13.1",
"tslint": "^4.4.2",
"tslint-react": "^2.3.0",
"typescript": "2.3.4",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.2.1",
"whatwg-fetch": "1.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/DariuS231/ChromeSPPropertiesAdmin.git"
},
"keywords": [
"SharePoint",
"PropertyBag",
"CSOM",
"JavaScript",
"Google Chrome",
"Chrome Extension"
],
"author": "Darius231",
"license": "MIT",
"bugs": {
"url": "https://github.com/DariuS231/ChromeSPPropertiesAdmin/issues"
},
"homepage": "https://github.com/DariuS231/ChromeSPPropertiesAdmin#readme"
}
6 changes: 3 additions & 3 deletions src/data/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"title": "Property bags",
"description": "Create, Update or Delete Web Property Bags.",
"image": "/images/sp-bag-64-blue.png",
"scriptUrl": "https://localhost:8080/dist/actions/SpPropertyBag/SpPropertyBag.js"
"scriptUrl": "https://localhost:8080/dist/actions/spPropertyBag/spPropertyBag.js"
},
{
"title": "Site lists",
"description": "All site lists, including hidden.",
"image": "/images/content-management-64-blue.png",
"scriptUrl": "https://localhost:8080/dist/actions/SpSiteContent/SpSiteContent.js"
"scriptUrl": "https://localhost:8080/dist/actions/spSiteContent/spSiteContent.js"
},
{
"title": "Site Custom Actions",
Expand All @@ -31,4 +31,4 @@
"scriptUrl": "https://localhost:8080/dist/actions/spFeatures/spFeatures.js"
}
]
}
}
5 changes: 1 addition & 4 deletions src/scripts/actions/common/AppBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ export class AppBase {
if (!baseDiv) {
baseDiv = document.createElement(constants.HTML_TAG_DIV);
baseDiv.setAttribute(constants.HTML_ATTR_ID, this.baseDivId);
let parentEl = document.querySelector(constants.HTML_TAG_FORM) as HTMLElement;
if (!parentEl) { // There is no Form element on modern pages, so the content gets add to the body instead
parentEl = document.querySelector(constants.HTML_TAG_BODY) as HTMLElement;
}
let parentEl = document.querySelector(constants.HTML_TAG_BODY) as HTMLElement;
parentEl.appendChild(baseDiv);
}
}
Expand Down
28 changes: 25 additions & 3 deletions src/scripts/actions/common/apiBase.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
import * as axios from "axios";
import { constants } from "./constants";
import { AppCache } from "./cache";

export default class ApiBase {
protected getErroResolver(reject: (reason?: any) => void, actionText: string): (sender: any, err: SP.ClientRequestFailedEventArgs) => void {

public getWebUrl(): Promise<string> {
return new Promise((resolve: (value?: string | PromiseLike<string>) => void, reject: (reason?: any) => void) => {
const cacheKey: string = `${window.location.href}_ChromeSPDevTools_url`;
let url: string = AppCache.get<string>(cacheKey);
if (!!url) {
resolve(url);
} else {
const ctx: SP.ClientContext = SP.ClientContext.get_current();
const web: SP.Web = ctx.get_web();
ctx.load(web);

ctx.executeQueryAsync(function () {
url = web.get_url();
AppCache.set(cacheKey, url);
resolve(url);
}, this.getErrorResolver(reject, constants.MESSAGE_GETTING_WEB_URL));
}
});
}

protected getErrorResolver(reject: (reason?: any) => void, actionText: string): (sender: any, err: SP.ClientRequestFailedEventArgs) => void {
return (sender: any, err: SP.ClientRequestFailedEventArgs): void => {
const errorMsg: string = err.get_message();
const errorTrace: string = err.get_stackTrace();
console.log("An error occured while " + actionText + "\nMessage: " + errorMsg + "\nError Trace: " + errorTrace);
console.log("An error occurred while " + actionText + "\nMessage: " + errorMsg + "\nError Trace: " + errorTrace);
reject(errorMsg);
}
}
Expand All @@ -32,7 +54,7 @@ export default class ApiBase {
const onSuccess = (sender: any, args: SP.ClientRequestSucceededEventArgs) => {
resolve(per.get_value());
};
ctx.executeQueryAsync(onSuccess, this.getErroResolver(reject, constants.MESSAGE_CHECKING_CURRENT_USER_PERMISSIONS));
ctx.executeQueryAsync(onSuccess, this.getErrorResolver(reject, constants.MESSAGE_CHECKING_CURRENT_USER_PERMISSIONS));
}
});

Expand Down
77 changes: 77 additions & 0 deletions src/scripts/actions/common/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

import { constants } from "./constants";

class Cache {
private _keyPrefix: string = "spChromeDevTool_";
private _isSupportedStorage: boolean = null;

public get isSupportedStorage(): boolean {
if (this._isSupportedStorage === null) {
this._isSupportedStorage = this.checkIfStorageIsSupported();
}
return this._isSupportedStorage;
}
public clear(key: string): void {
const completeKey: string = this.addKeyPrefix(key);
this.CacheObject.removeItem(completeKey);
}

public get<T>(key: string): T {
const completeKey: string = this.addKeyPrefix(key);
if (this.isSupportedStorage) {
const cachedDataStr = this.CacheObject.getItem(completeKey);

if (typeof cachedDataStr === constants.TYPE_OF_STRING) {
const cacheDataObj = JSON.parse(cachedDataStr);
if (cacheDataObj.expiryTime > (new Date())) {
return cacheDataObj.data;
}
}
}
return null;
}

public set(key: string, valueObj: any, expireMinutes?: number) {
const completeKey: string = this.addKeyPrefix(key);
let didSetInCache = false;
if (this.isSupportedStorage && valueObj !== undefined) {
const nowDt = new Date();
const expiryTime: number = (typeof expireMinutes !== constants.TYPE_OF_UNDEFINED)
? nowDt.setMinutes(nowDt.getMinutes() + expireMinutes)
: 8640000000000000;
const cacheDataObj: any = { data: valueObj, expiryTime };
this.CacheObject.setItem(completeKey, JSON.stringify(cacheDataObj));

didSetInCache = true;

}
return didSetInCache;
}

private addKeyPrefix(key: string): string {
return this._keyPrefix + window.location.href.replace(/:\/\/|\/|\./g, "_") + "_" + key;
}

private get CacheObject(): Storage {
return window.localStorage;
}
private checkIfStorageIsSupported() {
const cacheObj = this.CacheObject;
const supportsStorage = cacheObj && JSON
&& typeof JSON.parse === constants.TYPE_OF_FUNCTION
&& typeof JSON.stringify === constants.TYPE_OF_FUNCTION;
if (supportsStorage) {
try {
const testKey = this._keyPrefix + "testingCache";
cacheObj.setItem(testKey, "1");
cacheObj.removeItem(testKey);
return true;
} catch (ex) {
console.log("Local Storage not supported by the browser.");
}
}
return false;
}
}

export const AppCache: Cache = new Cache();
12 changes: 12 additions & 0 deletions src/scripts/actions/common/components/favouriteButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from "react";
import { IconButton } from "./iconButton";

interface IFavouriteButtonProps {
onClick: React.EventHandler<React.MouseEvent<HTMLAnchorElement>>;
isFavourite: boolean;
}
export const FavouriteButton: React.StatelessComponent<IFavouriteButtonProps> = (props: IFavouriteButtonProps) => {
const title: string = props.isFavourite ? "Unpin favourite" : "Pin as favourites";
const starType: string = props.isFavourite ? "FavoriteStarFill" : "FavoriteStar";
return <IconButton icon={starType} title={title} onClick={props.onClick} />;
};
2 changes: 2 additions & 0 deletions src/scripts/actions/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const constants = {
HTML_TAG_SCRIPT: "script",
MESSAGE_CANT_CHECK_PERMISSIONS: "Cannot check permissions against a non-securable object.",
MESSAGE_CHECKING_CURRENT_USER_PERMISSIONS: "Checking current's user permission",
MESSAGE_GETTING_WEB_URL: "Getting Web URL",
MODAL_WRAPPER_CLOSE_BUTTON_HREF: "javascript:void(0)",
MODAL_WRAPPER_CLOSE_BUTTON_TEXT: "Close",
SCRIPT_TAG_TYPE: "text/javascript",
Expand All @@ -22,6 +23,7 @@ export const constants = {
STYLE_TAG_ID: "spChromeDevToolStyles",
TYPE_OF_FUNCTION: "function",
TYPE_OF_UNDEFINED: "undefined",
TYPE_OF_STRING: "string",
URL_LAYOUTS: "/_layouts/15/",
URL_SLASH: "/",
URL_SP: "sp.js",
Expand Down
31 changes: 31 additions & 0 deletions src/scripts/actions/common/favouriteBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import { AppCache } from "./cache";

export class FavouritesBase {
private _favouriteArray: string[] = null;
private _favouriteCacheKey: string;

constructor(cacheKey: string) {
this._favouriteCacheKey = cacheKey;
}
public get Favourites(): string[]{
if (this._favouriteArray === null) {
this._favouriteArray = AppCache.get<string[]>(this._favouriteCacheKey) || [];
}
return this._favouriteArray;
}

public addToFavourites(guid: string) {
if (this.Favourites.indexOf(guid) === -1) {
this.Favourites.push(guid);
AppCache.set(this._favouriteCacheKey, this.Favourites);
}
}
public removeFromFavourites(guid: string) {
const index = this.Favourites.indexOf(guid);
if (index >= -1) {
this.Favourites.splice(index, 1);
AppCache.set(this._favouriteCacheKey, this.Favourites);
}
}
}
Loading

0 comments on commit 13b0715

Please sign in to comment.