From 9331e07c6e101bf6203df1c6f6d71a3015dc9063 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Mon, 23 May 2016 15:33:04 +0100 Subject: [PATCH 1/8] Fixed column translation problem --- .../ng2-alfresco-documentlist/package.json | 2 +- .../src/components/content-column-list.ts | 14 ++++++++++++++ .../src/components/content-column.ts | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ng2-components/ng2-alfresco-documentlist/package.json b/ng2-components/ng2-alfresco-documentlist/package.json index 733aa1d894..6e01f4aba6 100644 --- a/ng2-components/ng2-alfresco-documentlist/package.json +++ b/ng2-components/ng2-alfresco-documentlist/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-documentlist", "description": "Alfresco Angular2 Document List Component", - "version": "0.1.4", + "version": "0.1.5", "author": "Alfresco Software, Ltd.", "scripts": { "typings": "typings install", diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts index 42c745caf3..f7e511dd86 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts @@ -38,4 +38,18 @@ export class ContentColumnList { this.documentList.columns.push(column); } } + + /** + * Update the title with the new value + * @param column Column definition model. + */ + updateColumn(column: ContentColumnModel): void { + if (this.documentList && column) { + this.documentList.columns.forEach((tmpColumn) => { + if (tmpColumn.source === column.source) { + tmpColumn.title = column.title; + } + }); + } + } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts index 93a186875f..84824b33d0 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts @@ -58,4 +58,13 @@ export class ContentColumn implements OnInit { this.list.registerColumn(model); } } + + ngOnChanges(change) { + let model = new ContentColumnModel(); + model.title = this.title; + model.source = this.source; + if (this.list) { + this.list.updateColumn(model); + } + } } From 3f28925d35203c03067294321d3aa44c1e65c038 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 23 May 2016 16:11:20 +0100 Subject: [PATCH 2/8] #9 i18n fixes for columns and actions --- .../src/components/content-action.ts | 29 ++++++++++------ .../src/components/content-column-list.ts | 14 -------- .../src/components/content-column.ts | 33 ++++++++++--------- .../src/models/content-action.model.ts | 10 ++++++ .../src/models/content-column.model.ts | 9 +++++ 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts index 4b2b8c02ef..95dcf049f2 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-action.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import {Component, OnInit, Input, Output, EventEmitter} from 'angular2/core'; +import {Component, OnInit, OnChanges, Input, Output, EventEmitter} from 'angular2/core'; import {ContentActionModel} from './../models/content-action.model'; import {ContentActionList} from './content-action-list'; import {DocumentActionsService} from '../services/document-actions.service'; @@ -26,7 +26,7 @@ import {ContentActionHandler} from '../models/content-action.model'; selector: 'content-action', template: '' }) -export class ContentAction implements OnInit { +export class ContentAction implements OnInit, OnChanges { @Input() title: string = 'Action'; @@ -46,30 +46,39 @@ export class ContentAction implements OnInit { @Output() execute = new EventEmitter(); + model: ContentActionModel; + constructor( private list: ContentActionList, private documentActions: DocumentActionsService, private folderActions: FolderActionsService) { + this.model = new ContentActionModel(); } ngOnInit() { - let model = new ContentActionModel(); - model.type = this.type; - model.title = this.title; - model.icon = this.icon; - model.target = this.target; + this.model = new ContentActionModel({ + type: this.type, + title: this.title, + icon: this.icon, + target: this.target + }); if (this.handler) { - model.handler = this.getSystemHandler(this.target, this.handler); + this.model.handler = this.getSystemHandler(this.target, this.handler); } else if (this.execute) { - model.handler = (document: any): void => { + this.model.handler = (document: any): void => { this.execute.emit({ value: document }); }; } - this.list.registerAction(model); + this.list.registerAction(this.model); + } + + ngOnChanges() { + // update localizable properties + this.model.title = this.title; } private getSystemHandler(target: string, name: string): ContentActionHandler { diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts index f7e511dd86..42c745caf3 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column-list.ts @@ -38,18 +38,4 @@ export class ContentColumnList { this.documentList.columns.push(column); } } - - /** - * Update the title with the new value - * @param column Column definition model. - */ - updateColumn(column: ContentColumnModel): void { - if (this.documentList && column) { - this.documentList.columns.forEach((tmpColumn) => { - if (tmpColumn.source === column.source) { - tmpColumn.title = column.title; - } - }); - } - } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts index 84824b33d0..061b83feb1 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/content-column.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, OnInit, Input } from 'angular2/core'; +import { Component, OnInit, Input, OnChanges } from 'angular2/core'; import { ContentColumnList } from './content-column-list'; import { ContentColumnModel } from './../models/content-column.model'; @@ -23,7 +23,7 @@ import { ContentColumnModel } from './../models/content-column.model'; selector: 'content-column', template: '' }) -export class ContentColumn implements OnInit { +export class ContentColumn implements OnInit, OnChanges { @Input() title: string = ''; @@ -40,31 +40,32 @@ export class ContentColumn implements OnInit { @Input('class') cssClass: string; + model: ContentColumnModel; + constructor(private list: ContentColumnList) { + this.model = new ContentColumnModel(); } ngOnInit() { - let model = new ContentColumnModel(); - model.title = this.title; - model.srTitle = this.srTitle; - model.source = this.source; - model.cssClass = this.cssClass; + this.model = new ContentColumnModel({ + title: this.title, + srTitle: this.srTitle, + source: this.source, + cssClass: this.cssClass + }); - if (!model.srTitle && model.source === '$thumbnail') { - model.srTitle = 'Thumbnail'; + if (!this.model.srTitle && this.model.source === '$thumbnail') { + this.model.srTitle = 'Thumbnail'; } if (this.list) { - this.list.registerColumn(model); + this.list.registerColumn(this.model); } } ngOnChanges(change) { - let model = new ContentColumnModel(); - model.title = this.title; - model.source = this.source; - if (this.list) { - this.list.updateColumn(model); - } + // update localizable properties + this.model.title = this.title; + this.model.srTitle = this.srTitle; } } diff --git a/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts b/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts index 23797e6202..bfd303d523 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/models/content-action.model.ts @@ -21,6 +21,16 @@ export class ContentActionModel { handler: ContentActionHandler; type: string; target: string; + + constructor(obj?: any) { + if (obj) { + this.icon = obj.icon; + this.title = obj.title; + this.handler = obj.handler; + this.type = obj.type; + this.target = obj.target; + } + } } export interface ContentActionHandler { diff --git a/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts b/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts index 8ea94acc53..24ff9fcf0b 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/models/content-column.model.ts @@ -20,4 +20,13 @@ export class ContentColumnModel { srTitle: string; source: string; cssClass: string; + + constructor(obj?: any) { + if (obj) { + this.title = obj.title; + this.srTitle = obj.srTitle; + this.source = obj.source; + this.cssClass = obj.cssClass; + } + } } From 339b84f042e74d16c40da24226c6b6c6c40da7db Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Mon, 23 May 2016 17:32:01 +0100 Subject: [PATCH 3/8] Removed ng-translate code from the core Added ng-translate dependency --- demo-shell-ng2/package.json | 1 + demo-shell-ng2/systemjs.config.js | 4 +- ng2-components/ng2-alfresco-core/package.json | 5 +- .../services/AlfrescoPipeTranslate.service.ts | 146 +------- .../AlfrescoTranslationLoader.service.ts | 2 +- .../AlfrescoTranslationService.service.ts | 319 +----------------- .../src/services/translate.parser.ts | 65 ---- .../ng2-alfresco-login/demo/index.html | 1 + .../ng2-alfresco-login/demo/package.json | 1 + .../ng2-alfresco-login/karma-test-shim.js | 6 +- .../ng2-alfresco-login/karma.conf.js | 1 + .../ng2-alfresco-login/package.json | 5 +- .../ng2-alfresco-upload/demo/index.html | 1 + .../ng2-alfresco-upload/demo/package.json | 1 + .../ng2-alfresco-upload/karma-test-shim.js | 6 +- .../ng2-alfresco-upload/karma.conf.js | 1 + .../ng2-alfresco-upload/package.json | 5 +- 17 files changed, 44 insertions(+), 526 deletions(-) delete mode 100644 ng2-components/ng2-alfresco-core/src/services/translate.parser.ts diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 2b1c84c58c..81930af8d9 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -53,6 +53,7 @@ "ng2-alfresco-login": "^0.1.0", "ng2-alfresco-search": "^0.1.2", "ng2-alfresco-upload": "^0.1.0", + "ng2-translate": "^1.11.3", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "systemjs": "0.19.26", diff --git a/demo-shell-ng2/systemjs.config.js b/demo-shell-ng2/systemjs.config.js index 4a6ac9eb70..757e94a293 100644 --- a/demo-shell-ng2/systemjs.config.js +++ b/demo-shell-ng2/systemjs.config.js @@ -25,7 +25,8 @@ 'ng2-alfresco-login': 'node_modules/ng2-alfresco-login', 'ng2-alfresco-search': 'node_modules/ng2-alfresco-search', 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload', - 'rxjs': 'node_modules/rxjs' + 'rxjs': 'node_modules/rxjs', + 'ng2-translate': 'node_modules/ng2-translate' }; // packages tells the System loader how to load when no filename and/or no extension @@ -40,6 +41,7 @@ 'ng2-alfresco-login': {defaultExtension: 'js'}, 'ng2-alfresco-search': {defaultExtension: 'js'}, 'ng2-alfresco-upload': {defaultExtension: 'js'}, + 'ng2-translate': {defaultExtension: 'js'}, 'rxjs': {defaultExtension: 'js'} }; diff --git a/ng2-components/ng2-alfresco-core/package.json b/ng2-components/ng2-alfresco-core/package.json index 7898a8e678..1722240a04 100644 --- a/ng2-components/ng2-alfresco-core/package.json +++ b/ng2-components/ng2-alfresco-core/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-core", "description": "Alfresco Angular 2 Components core", - "version": "0.1.19", + "version": "0.1.20", "author": "Alfresco Software, Ltd.", "scripts": { "typings": "typings install", @@ -53,7 +53,8 @@ "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "systemjs": "0.19.26", - "zone.js": "^0.6.12" + "zone.js": "^0.6.12", + "ng2-translate": "^1.11.3" }, "peerDependencies": { "angular2": "2.0.0-beta.15" diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts index 02a109db98..bc6b17f1f0 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoPipeTranslate.service.ts @@ -15,152 +15,18 @@ * limitations under the License. */ -import { PipeTransform, Pipe, Injectable, EventEmitter, OnDestroy, ChangeDetectorRef } from 'angular2/core'; -import { AlfrescoTranslationService, LangChangeEvent } from './AlfrescoTranslationService.service'; -import { isPresent, isArray } from 'angular2/src/facade/lang'; +import { Injectable, ChangeDetectorRef, Pipe } from 'angular2/core'; +import { TranslatePipe } from 'ng2-translate/ng2-translate'; +import { AlfrescoTranslationService } from './AlfrescoTranslationService.service'; @Injectable() @Pipe({ name: 'translate', pure: false // required to update the value when the promise is resolved }) -export class AlfrescoPipeTranslate implements PipeTransform, OnDestroy { - value: string = ''; - lastKey: string; - lastParams: any[]; - onLangChange: EventEmitter; +export class AlfrescoPipeTranslate extends TranslatePipe { - constructor(private translate: AlfrescoTranslationService, private _ref: ChangeDetectorRef) { - } - - /** - * @name equals - * - * @description - * Determines if two objects or two values are equivalent. - * - * Two objects or values are considered equivalent if at least one of the following is true: - * - * * Both objects or values pass `===` comparison. - * * Both objects or values are of the same type and all of their properties are equal by - * comparing them with `equals`. - * - * @param {*} o1 Object or value to compare. - * @param {*} o2 Object or value to compare. - * @returns {boolean} True if arguments are equal. - */ - private equals(o1: any, o2: any): boolean { - if (o1 === o2) { - return true; - } - if (o1 === null || o2 === null) { - return false; - } - if (o1 !== o1 && o2 !== o2) { - return true; - } // NaN === NaN - let t1 = typeof o1, t2 = typeof o2, length: number, key: any, keySet: any; - if (t1 === t2 && t1 === 'object') { - if (isArray(o1)) { - if (!isArray(o2)) { - return false; - } - length = o1.length; - if (length === o2.length) { - for (key = 0; key < length; key++) { - if (!this.equals(o1[key], o2[key])) { - return false; - } - } - return true; - } - } else { - if (isArray(o2)) { - return false; - } - keySet = Object.create(null); - for (key in o1) { - if (key) { - if (!this.equals(o1[key], o2[key])) { - return false; - } - keySet[key] = true; - } - } - for (key in o2) { - if (!(key in keySet) && typeof o2[key] !== 'undefined') { - return false; - } - } - return true; - } - } - return false; - } - - updateValue(key: string, interpolateParams?: Object): void { - this.translate.get(key, interpolateParams).subscribe((res: string) => { - this.value = res ? res : key; - this._ref.markForCheck(); - }); - } - - transform(query: string, ...args: any[]): any { - if (!query || query.length === 0) { - return query; - } - // if we ask another time for the same key, return the last value - if (this.equals(query, this.lastKey) && this.equals(args, this.lastParams)) { - return this.value; - } - - let interpolateParams: Object; - if (args.length && args[0] !== null) { - if (typeof args[0] === 'string' && args[0].length) { - // we accept objects written in the template such as {n:1}, - // which is why we might need to change it to real JSON objects such as {"n":1} - try { - interpolateParams = JSON.parse(args[0].replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": ')); - } catch (e) { - throw new SyntaxError(`Wrong parameter in TranslatePipe. Expected a valid Object, received: ${args[0]}`); - } - } else if (typeof args[0] === 'object' && !Array.isArray(args[0])) { - interpolateParams = args[0]; - } - } - - // store the query, in case it changes - this.lastKey = query; - - // store the params, in case they change - this.lastParams = args; - - // set the value - this.updateValue(query, interpolateParams); - - // if there is a subscription to onLangChange, clean it - this._dispose(); - - // subscribe to onLangChange event, in case the language changes - this.onLangChange = this.translate.onLangChange.subscribe((event: LangChangeEvent) => { - this.updateValue(query, interpolateParams); - }); - - return this.value; - } - - /** - * Clean any existing subscription to onLangChange events - * @private - */ - _dispose(): void { - if (isPresent(this.onLangChange)) { - this.onLangChange.unsubscribe(); - this.onLangChange = undefined; - } - } - - ngOnDestroy(): void { - this._dispose(); + constructor(translate: AlfrescoTranslationService, _ref: ChangeDetectorRef) { + super(translate, _ref); } } diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationLoader.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationLoader.service.ts index 244ed767c6..7d214cd132 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationLoader.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationLoader.service.ts @@ -18,7 +18,7 @@ import { Injectable } from 'angular2/core'; import { Response, Http } from 'angular2/http'; import { Observable } from 'rxjs/Observable'; -import { TranslateLoader } from './AlfrescoTranslationService.service'; +import { TranslateLoader } from 'ng2-translate/ng2-translate'; @Injectable() export class AlfrescoTranslationLoader implements TranslateLoader { diff --git a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts index b3feda3a58..d10ae9e8e8 100644 --- a/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/AlfrescoTranslationService.service.ts @@ -15,87 +15,18 @@ * limitations under the License. */ -import { Injectable, Optional, EventEmitter } from 'angular2/core'; +import { Injectable, Optional } from 'angular2/core'; +import { Http } from 'angular2/http'; +import { MissingTranslationHandler, TranslateService } from 'ng2-translate/ng2-translate'; import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service'; -import { Http, Response } from 'angular2/http'; -import { Observable } from 'rxjs/Observable'; -import { Observer } from 'rxjs/Observer'; -import 'rxjs/add/observable/of'; -import 'rxjs/add/operator/share'; -import 'rxjs/add/operator/map'; -import 'rxjs/add/operator/merge'; -import 'rxjs/add/operator/toArray'; - -import { Parser } from './translate.parser'; - -export interface LangChangeEvent { - lang: string; - translations: any; -} - -export abstract class MissingTranslationHandler { - /** - * A function that handles missing translations. - * @param key the missing key - * @returns {any} a value or an observable - * If it returns a value, then this value is used. - * If it return an observable, the value returned by this observable will be used (except if the method was "instant"). - * If it doesn't return then the key will be used as a value - */ - abstract handle(key: string): any; -} - -export abstract class TranslateLoader { - abstract getTranslation(lang: string): Observable; -} - -export class TranslateStaticLoader implements TranslateLoader { - constructor(private http: Http, private prefix: string = 'i18n', private suffix: string = '.json') { - } - - /** - * Gets the translations from the server - * @param lang - * @returns {any} - */ - public getTranslation(lang: string): Observable { - return this.http.get(`${this.prefix}/${lang}${this.suffix}`) - .map((res: Response) => res.json()); - } -} @Injectable() -export class AlfrescoTranslationService { - /** - * The lang currently used - */ - public currentLang: string = this.defaultLang; +export class AlfrescoTranslationService extends TranslateService { + userLang: string = 'en' ; + currentLoader: AlfrescoTranslationLoader; - /** - * An EventEmitter to listen to lang changes events - * onLangChange.subscribe((params: LangChangeEvent) => { - * // do something - * }); - * @type {ng.EventEmitter} - */ - public onLangChange: EventEmitter = new EventEmitter(); - - private pending: any; - private translations: any = {}; - private defaultLang: string; - private langs: Array; - private parser: Parser = new Parser(); - - userLang: string = 'en'; - - /** - * - * @param http The Angular 2 http provider - * @param currentLoader An instance of the loader currently used - * @param missingTranslationHandler A handler for missing translations. - */ - constructor(private http: Http, public currentLoader: AlfrescoTranslationLoader, @Optional() - private missingTranslationHandler: MissingTranslationHandler) { + constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) { + super(http, currentLoader, missingTranslationHandler); } translationInit(name: string = ''): void { @@ -113,238 +44,4 @@ export class AlfrescoTranslationService { this.getTranslation(this.userLang); } } - - /** - * Sets the default language to use as a fallback - * @param lang - */ - public setDefaultLang(lang: string): void { - this.defaultLang = lang; - } - - /** - * Changes the lang currently used - * @param lang - * @returns {Observable<*>} - */ - public use(lang: string): Observable { - let pending: Observable; - // check if this language is available - if (typeof this.translations[lang] === 'undefined') { - // not available, ask for it - pending = this.getTranslation(lang); - } - - if (typeof pending !== 'undefined') { - pending.subscribe((res: any) => { - this.changeLang(lang); - }); - - return pending; - } else { // we have this language, return an Observable - this.changeLang(lang); - - return Observable.of(this.translations[lang]); - } - } - - /** - * Gets an object of translations for a given language with the current loader - * @param lang - * @returns {Observable<*>} - */ - public getTranslation(lang: string): Observable { - this.pending = this.currentLoader.getTranslation(lang).share(); - this.pending.subscribe((res: Object) => { - this.translations[lang] = res; - this.updateLangs(); - }, (err: any) => { - throw err; - }, () => { - this.pending = undefined; - }); - - return this.pending; - } - - /** - * Manually sets an object of translations for a given language - * @param lang - * @param translations - */ - public setTranslation(lang: string, translations: Object): void { - this.translations[lang] = translations; - this.updateLangs(); - } - - /** - * Returns an array of currently available langs - * @returns {any} - */ - public getLangs(): Array { - return this.langs; - } - - /** - * Update the list of available langs - */ - private updateLangs(): void { - this.langs = Object.keys(this.translations); - } - - /** - * Returns the parsed result of the translations - * @param translations - * @param key - * @param interpolateParams - * @returns {any} - */ - private getParsedResult(translations: any, key: any, interpolateParams?: Object): any { - let res: string|Observable; - - if (key instanceof Array) { - let result: any = {}, - observables: boolean = false; - for (let k of key) { - result[k] = this.getParsedResult(translations, k, interpolateParams); - if (typeof result[k].subscribe === 'function') { - observables = true; - } - } - if (observables) { - let mergedObs: any; - for (let k of key) { - let obs = typeof result[k].subscribe === 'function' ? result[k] : Observable.of(result[k]); - if (typeof mergedObs === 'undefined') { - mergedObs = obs; - } else { - mergedObs = mergedObs.merge(obs); - } - } - return mergedObs.toArray().map((arr: Array) => { - let obj: any = {}; - arr.forEach((value: string, index: number) => { - obj[key[index]] = value; - }); - return obj; - }); - } - return result; - } - - if (translations) { - res = this.parser.interpolate(this.parser.getValue(translations, key), interpolateParams); - } - - if (typeof res === 'undefined' && this.defaultLang && this.defaultLang !== this.currentLang) { - res = this.parser.interpolate(this.parser.getValue(this.translations[this.defaultLang], key), interpolateParams); - } - - if (!res && this.missingTranslationHandler) { - res = this.missingTranslationHandler.handle(key); - } - - return res || key; - } - - /** - * Gets the translated value of a key (or an array of keys) - * @param key - * @param interpolateParams - * @returns {any} the translated key, or an object of translated keys - */ - public get(key: string|Array, interpolateParams?: Object): Observable { - if (!key) { - throw new Error('Parameter "key" required'); - } - // check if we are loading a new translation to use - if (this.pending) { - return Observable.create((observer: Observer) => { - let onComplete = (res: string) => { - observer.next(res); - observer.complete(); - }; - this.pending.subscribe((resSub: any) => { - let res = this.getParsedResult(resSub, key, interpolateParams); - if (typeof res.subscribe === 'function') { - res.subscribe(onComplete); - } else { - onComplete(res); - } - }); - }); - } else { - let res = this.getParsedResult(this.translations[this.currentLang], key, interpolateParams); - if (typeof res.subscribe === 'function') { - return res; - } else { - return Observable.of(res); - } - } - } - - /** - * Returns a translation instantly from the internal state of loaded translation. - * All rules regarding the current language, the preferred language of even fallback languages will be used except any promise handling. - * @param key - * @param interpolateParams - * @returns {string} - */ - public instant(key: string|Array, interpolateParams?: Object): string|any { - if (!key) { - throw new Error('Parameter "key" required'); - } - - let res = this.getParsedResult(this.translations[this.currentLang], key, interpolateParams); - if (typeof res.subscribe !== 'undefined') { - if (key instanceof Array) { - let obj: any = {}; - key.forEach((value: string, index: number) => { - obj[key[index]] = key[index]; - }); - return obj; - } - return key; - } else { - return res; - } - } - - /** - * Sets the translated value of a key - * @param key - * @param value - * @param lang - */ - public set(key: string, value: string, lang: string = this.currentLang): void { - this.translations[lang][key] = value; - this.updateLangs(); - } - - /** - * Changes the current lang - * @param lang - */ - private changeLang(lang: string): void { - this.currentLang = lang; - this.onLangChange.emit({lang: lang, translations: this.translations[lang]}); - } - - /** - * Allows to reload the lang file from the file - * @param lang - * @returns {Observable} - */ - public reloadLang(lang: string): Observable { - this.resetLang(lang); - return this.getTranslation(lang); - } - - /** - * Deletes inner translation - * @param lang - */ - public resetLang(lang: string): void { - this.translations[lang] = undefined; - } } diff --git a/ng2-components/ng2-alfresco-core/src/services/translate.parser.ts b/ng2-components/ng2-alfresco-core/src/services/translate.parser.ts deleted file mode 100644 index 217db9edee..0000000000 --- a/ng2-components/ng2-alfresco-core/src/services/translate.parser.ts +++ /dev/null @@ -1,65 +0,0 @@ -/*! - * @license - * Copyright 2016 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export class Parser { - templateMatcher: RegExp = /{{\s?([^{}\s]*)\s?}}/g; - - - /** - * Interpolates a string to replace parameters - * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" } - * @param expr - * @param params - * @returns {string} - */ - public interpolate(expr: string, params?: any): string { - if (typeof expr !== 'string' || !params) { - return expr; - } - - return expr.replace(this.templateMatcher, (substring: string, b: string) => { - let r = this.getValue(params, b); - return typeof r !== 'undefined' ? r : substring; - }); - } - - /** - * Gets a value from an object by composed key - * parser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI' - * @param target - * @param key - * @returns {string} - */ - public getValue(target: any, key: string): string { - let keys = key.split('.'); - key = ''; - do { - key += keys.shift(); - if (target[key] !== undefined && (typeof target[key] === 'object' || !keys.length)) { - target = target[key]; - key = ''; - } else if (!keys.length) { - target = undefined; - } else { - key += '.'; - } - } while (keys.length); - - return target; - } - -} diff --git a/ng2-components/ng2-alfresco-login/demo/index.html b/ng2-components/ng2-alfresco-login/demo/index.html index 225bfa70dc..9d31e0a7e8 100644 --- a/ng2-components/ng2-alfresco-login/demo/index.html +++ b/ng2-components/ng2-alfresco-login/demo/index.html @@ -26,6 +26,7 @@ 'ng2-translate': 'node_modules/ng2-translate', 'rxjs': 'node_modules/rxjs', 'angular2' : 'node_modules/angular2', + 'ng2-translate' : 'node_modules/ng2-translate', 'app': 'dist/src' }, packages: { diff --git a/ng2-components/ng2-alfresco-login/demo/package.json b/ng2-components/ng2-alfresco-login/demo/package.json index 14824dc266..3de2324449 100644 --- a/ng2-components/ng2-alfresco-login/demo/package.json +++ b/ng2-components/ng2-alfresco-login/demo/package.json @@ -17,6 +17,7 @@ "es6-promise": "3.0.2", "es6-shim": "0.35.0", "ng2-alfresco-login": "^0.1.0", + "ng2-translate": "^1.11.3", "ng2-translate": "^1.11.2", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", diff --git a/ng2-components/ng2-alfresco-login/karma-test-shim.js b/ng2-components/ng2-alfresco-login/karma-test-shim.js index 5544ce9a11..cc5318401e 100644 --- a/ng2-components/ng2-alfresco-login/karma-test-shim.js +++ b/ng2-components/ng2-alfresco-login/karma-test-shim.js @@ -17,13 +17,17 @@ System.config({ 'ng2-alfresco-core/dist': { defaultExtension: 'js' }, + 'ng2-translate': { + defaultExtension: 'js' + }, 'rxjs': { defaultExtension: 'js' } }, map: { 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist', - 'rxjs': '/base/node_modules/rxjs' + 'rxjs': '/base/node_modules/rxjs', + 'ng2-translate' : '/base/node_modules/ng2-translate' } }); diff --git a/ng2-components/ng2-alfresco-login/karma.conf.js b/ng2-components/ng2-alfresco-login/karma.conf.js index 0018f4f76d..f010b27088 100644 --- a/ng2-components/ng2-alfresco-login/karma.conf.js +++ b/ng2-components/ng2-alfresco-login/karma.conf.js @@ -18,6 +18,7 @@ module.exports = function (config) { {pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false}, {pattern: 'node_modules/alfresco-core-rest-api/bundle.js', included: true, watched: false}, {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false}, {pattern: 'karma-test-shim.js', included: true, watched: true}, diff --git a/ng2-components/ng2-alfresco-login/package.json b/ng2-components/ng2-alfresco-login/package.json index aecc6f779a..0c53232b70 100644 --- a/ng2-components/ng2-alfresco-login/package.json +++ b/ng2-components/ng2-alfresco-login/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-login", "description": "Alfresco Angular2 Login Component", - "version": "0.1.6", + "version": "0.1.7", "author": "Alfresco Software, Ltd.", "scripts": { "typings": "typings install", @@ -63,7 +63,8 @@ "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "systemjs": "0.19.26", - "zone.js": "^0.6.12" + "zone.js": "^0.6.12", + "ng2-translate": "^1.11.3" }, "peerDependencies": { "angular2": "2.0.0-beta.15" diff --git a/ng2-components/ng2-alfresco-upload/demo/index.html b/ng2-components/ng2-alfresco-upload/demo/index.html index f6bc1c8bd5..2cf06a9b90 100644 --- a/ng2-components/ng2-alfresco-upload/demo/index.html +++ b/ng2-components/ng2-alfresco-upload/demo/index.html @@ -31,6 +31,7 @@ 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload', 'rxjs': 'node_modules/rxjs', 'angular2' : 'node_modules/angular2', + 'ng2-translate' : 'node_modules/ng2-translate', 'app': 'dist/src' }, packages: { diff --git a/ng2-components/ng2-alfresco-upload/demo/package.json b/ng2-components/ng2-alfresco-upload/demo/package.json index e4d3b6cb18..443ff45cd9 100644 --- a/ng2-components/ng2-alfresco-upload/demo/package.json +++ b/ng2-components/ng2-alfresco-upload/demo/package.json @@ -21,6 +21,7 @@ "material-design-lite": "^1.1.3", "ng2-alfresco-core": "^0.1.6", "ng2-alfresco-upload": "^0.1.0", + "ng2-translate": "^1.11.3", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "zone.js": "0.6.6" diff --git a/ng2-components/ng2-alfresco-upload/karma-test-shim.js b/ng2-components/ng2-alfresco-upload/karma-test-shim.js index d283790f5d..62d31180b8 100644 --- a/ng2-components/ng2-alfresco-upload/karma-test-shim.js +++ b/ng2-components/ng2-alfresco-upload/karma-test-shim.js @@ -17,13 +17,17 @@ System.config({ 'ng2-alfresco-core/dist': { defaultExtension: 'js' }, + 'ng2-translate': { + defaultExtension: 'js' + }, 'rxjs': { defaultExtension: 'js' } }, map: { 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist', - 'rxjs': '/base/node_modules/rxjs' + 'rxjs': '/base/node_modules/rxjs', + 'ng2-translate' : '/base/node_modules/ng2-translate' } }); diff --git a/ng2-components/ng2-alfresco-upload/karma.conf.js b/ng2-components/ng2-alfresco-upload/karma.conf.js index dff754de67..c4853fdd0b 100644 --- a/ng2-components/ng2-alfresco-upload/karma.conf.js +++ b/ng2-components/ng2-alfresco-upload/karma.conf.js @@ -18,6 +18,7 @@ module.exports = function (config) { {pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false}, {pattern: 'node_modules/alfresco-core-rest-api/bundle.js', included: true, watched: false}, {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false}, + {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false}, {pattern: 'karma-test-shim.js', included: true, watched: true}, diff --git a/ng2-components/ng2-alfresco-upload/package.json b/ng2-components/ng2-alfresco-upload/package.json index fffd463a58..c5d6a26ec6 100644 --- a/ng2-components/ng2-alfresco-upload/package.json +++ b/ng2-components/ng2-alfresco-upload/package.json @@ -1,7 +1,7 @@ { "name": "ng2-alfresco-upload", "description": "Alfresco Angular2 Upload Component", - "version": "0.1.9", + "version": "0.1.10", "author": "Alfresco Software, Ltd.", "scripts": { "typings": "typings install", @@ -55,7 +55,8 @@ "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", "systemjs": "0.19.26", - "zone.js": "^0.6.12" + "zone.js": "^0.6.12", + "ng2-translate": "^1.11.3" }, "peerDependencies": { "angular2": "2.0.0-beta.15" From e9505b6cd24c3c26c8806edf7cda219bfb0ebbb8 Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Mon, 23 May 2016 18:30:05 +0100 Subject: [PATCH 4/8] fix demo folder --- demo-shell-ng2/package.json | 8 + ng2-components/ng2-alfresco-upload/README.md | 1 + .../ng2-alfresco-upload/demo/.editorconfig | 10 + .../ng2-alfresco-upload/demo/.gitignore | 7 +- .../ng2-alfresco-upload/demo/LICENSE | 190 ++++++++++++++++-- .../ng2-alfresco-upload/demo/README.md | 2 +- .../ng2-alfresco-upload/demo/index.html | 15 +- .../ng2-alfresco-upload/demo/package.json | 96 +++++---- .../demo/src/{my-app.ts => main.ts} | 0 .../ng2-alfresco-upload/demo/tsconfig.json | 32 +-- .../ng2-alfresco-upload/demo/tslint.json | 122 +++++++++++ .../ng2-alfresco-upload/demo/typings.json | 5 +- 12 files changed, 402 insertions(+), 86 deletions(-) create mode 100644 ng2-components/ng2-alfresco-upload/demo/.editorconfig rename ng2-components/ng2-alfresco-upload/demo/src/{my-app.ts => main.ts} (100%) create mode 100644 ng2-components/ng2-alfresco-upload/demo/tslint.json diff --git a/demo-shell-ng2/package.json b/demo-shell-ng2/package.json index 81930af8d9..23b32027a7 100644 --- a/demo-shell-ng2/package.json +++ b/demo-shell-ng2/package.json @@ -30,6 +30,14 @@ { "name": "Will Abson", "email": "will.abson@alfresco.com" + }, + { + "name": "Eugenio Romano", + "email": "eugenio.romano@alfresco.com" + }, + { + "name": "Maurizio Vitale", + "email": "maurizio.vitale@alfresco.com" } ], "keywords": [ diff --git a/ng2-components/ng2-alfresco-upload/README.md b/ng2-components/ng2-alfresco-upload/README.md index dacea2959a..fa439d361c 100644 --- a/ng2-components/ng2-alfresco-upload/README.md +++ b/ng2-components/ng2-alfresco-upload/README.md @@ -52,6 +52,7 @@ Make sure your systemjs.config has the following configuration: 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload', 'rxjs': 'node_modules/rxjs', 'angular2' : 'node_modules/angular2', + 'ng2-translate': 'node_modules/ng2-translate', 'app': 'dist/src' }, packages: { diff --git a/ng2-components/ng2-alfresco-upload/demo/.editorconfig b/ng2-components/ng2-alfresco-upload/demo/.editorconfig new file mode 100644 index 0000000000..8ed330c4a2 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/demo/.editorconfig @@ -0,0 +1,10 @@ + +root = true + +[{src,scripts}/**.{ts,json,js}] +end_of_line = crlf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 diff --git a/ng2-components/ng2-alfresco-upload/demo/.gitignore b/ng2-components/ng2-alfresco-upload/demo/.gitignore index d728305c75..67ecd66acc 100644 --- a/ng2-components/ng2-alfresco-upload/demo/.gitignore +++ b/ng2-components/ng2-alfresco-upload/demo/.gitignore @@ -1,5 +1,4 @@ -node_modules +typings/ +node_modules/ .idea -coverage -dist -typings \ No newline at end of file +dist/ \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/demo/LICENSE b/ng2-components/ng2-alfresco-upload/demo/LICENSE index 059fc6c668..430d42bbea 100644 --- a/ng2-components/ng2-alfresco-upload/demo/LICENSE +++ b/ng2-components/ng2-alfresco-upload/demo/LICENSE @@ -1,21 +1,177 @@ -The MIT License (MIT) -Copyright (c) 2016 Raúl Jiménez + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. +1. Definitions. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/ng2-components/ng2-alfresco-upload/demo/README.md b/ng2-components/ng2-alfresco-upload/demo/README.md index 9f87666579..c1bbd730d3 100644 --- a/ng2-components/ng2-alfresco-upload/demo/README.md +++ b/ng2-components/ng2-alfresco-upload/demo/README.md @@ -1,4 +1,4 @@ -# angular2-testing +# angular2-alfresco-upload Install: diff --git a/ng2-components/ng2-alfresco-upload/demo/index.html b/ng2-components/ng2-alfresco-upload/demo/index.html index 2cf06a9b90..57cb4a3369 100644 --- a/ng2-components/ng2-alfresco-upload/demo/index.html +++ b/ng2-components/ng2-alfresco-upload/demo/index.html @@ -2,7 +2,7 @@ - Angular 2 Upload + Alfresco Angular 2 Upload - Demo @@ -30,12 +30,12 @@ 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core', 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload', 'rxjs': 'node_modules/rxjs', - 'angular2' : 'node_modules/angular2', - 'ng2-translate' : 'node_modules/ng2-translate', - 'app': 'dist/src' + 'angular2': 'node_modules/angular2', + 'ng2-translate': 'node_modules/ng2-translate', + 'src': 'src' }, packages: { - 'app': { + 'src': { defaultExtension: 'js' }, 'ng2-alfresco-core': { @@ -52,8 +52,7 @@ } } }); - - System.import('dist/my-app').catch(console.log.bind(console)); + System.import('src/main').catch(console.log.bind(console)); @@ -62,4 +61,4 @@ - + \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/demo/package.json b/ng2-components/ng2-alfresco-upload/demo/package.json index 443ff45cd9..83fa263c16 100644 --- a/ng2-components/ng2-alfresco-upload/demo/package.json +++ b/ng2-components/ng2-alfresco-upload/demo/package.json @@ -1,42 +1,66 @@ { - "name": "ng2-alfresco-upload-demo", - "description": "Alfresco Angular2 Upload Component - Demo", - "version": "0.1.0", - "author": "Alfresco Software, Ltd.", - "main": "index.js", - "scripts": { - "postinstall": "npm run build && npm run typings", - "typings": "typings install", - "start": "rm -rf dist && npm install && npm run server", - "server" : "http-server -c-1 -o -p 8875 .", - "build": "rm -rf dist && tsc" + "name": "ng2-alfresco-upload-demo", + "description": "Alfresco Angular2 Upload Component - Demo", + "version": "0.1.0", + "author": "Alfresco Software, Ltd.", + "main": "index.js", + "scripts": { + "postinstall": "npm run build && npm run typings", + "typings": "typings install", + "start": "rm -rf dist && npm install && npm run server", + "server": "lite-server", + "build": "rm -rf dist && tsc" + }, + "license": "Apache-2.0", + "contributors": [ + { + "name": "Denys Vuika", + "email": "denis.vuyka@gmail.com" }, - "license": "MIT", - "dependencies": { - "alfresco-core-rest-api": "^0.1.0", - "angular2": "2.0.0-beta.15", - "es6-promise": "3.0.2", - "es6-shim": "0.35.0", - "material-design-icons": "^2.2.3", - "material-design-lite": "^1.1.3", - "ng2-alfresco-core": "^0.1.6", - "ng2-alfresco-upload": "^0.1.0", - "ng2-translate": "^1.11.3", - "reflect-metadata": "0.1.2", - "rxjs": "5.0.0-beta.2", - "zone.js": "0.6.6" + { + "name": "Mario Romano", + "email": "mario.romano83@gmail.com" }, - "devDependencies": { - "http-server": "0.8.5", - "systemjs": "0.19.17", - "typescript": "^1.8.10", - "typings": "^0.7.12" + { + "name": "Will Abson", + "email": "will.abson@alfresco.com" }, - "keywords": [ - "angular2", - "typescript" - ], - "publishConfig": { - "registry": "http://devproducts.alfresco.me:4873/" + { + "name": "Eugenio Romano", + "email": "eugenio.romano@alfresco.com" + }, + { + "name": "Maurizio Vitale", + "email": "maurizio.vitale@alfresco.com" } + ], + "keywords": [ + "ng2", + "angular", + "angular2", + "alfresco" + ], + "dependencies": { + "alfresco-core-rest-api": "^0.1.0", + "angular2": "2.0.0-beta.15", + "es6-shim": "^0.35.0", + "material-design-icons": "^2.2.3", + "material-design-lite": "^1.1.3", + "ng2-alfresco-core": "^0.1.0", + "ng2-alfresco-upload": "^0.1.0", + "reflect-metadata": "0.1.2", + "rxjs": "5.0.0-beta.2", + "systemjs": "0.19.26", + "zone.js": "0.6.10" + }, + "devDependencies": { + "browser-sync": "^2.10.0", + "concurrently": "^2.0.0", + "lite-server": "^2.2.0", + "typescript": "^1.8.10", + "typings": "^0.7.12" + }, + "publishConfig": { + "registry": "http://devproducts.alfresco.me:4873/" + } } diff --git a/ng2-components/ng2-alfresco-upload/demo/src/my-app.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts similarity index 100% rename from ng2-components/ng2-alfresco-upload/demo/src/my-app.ts rename to ng2-components/ng2-alfresco-upload/demo/src/main.ts diff --git a/ng2-components/ng2-alfresco-upload/demo/tsconfig.json b/ng2-components/ng2-alfresco-upload/demo/tsconfig.json index 0c6b9dc687..eaa102b97b 100644 --- a/ng2-components/ng2-alfresco-upload/demo/tsconfig.json +++ b/ng2-components/ng2-alfresco-upload/demo/tsconfig.json @@ -1,18 +1,18 @@ { - "compilerOptions": { - "target": "ES5", - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "sourceMap": true, - "removeComments": true, - "declaration": true, - "outDir": "dist" - }, - "exclude": [ - "node_modules", - "typings", - "dist" - ] + "compilerOptions": { + "target": "es5", + "module": "system", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "removeComments": true, + "declaration": true, + "outDir": "dist" + }, + "exclude": [ + "dist", + "node_modules", + "typings" + ] } diff --git a/ng2-components/ng2-alfresco-upload/demo/tslint.json b/ng2-components/ng2-alfresco-upload/demo/tslint.json new file mode 100644 index 0000000000..ce80085e69 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/demo/tslint.json @@ -0,0 +1,122 @@ +{ + "rules": { + "align": [ + true, + "parameters", + "arguments", + "statements" + ], + "ban": false, + "class-name": true, + "comment-format": [ + true, + "check-space", + "check-lowercase" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "interface-name": false, + "jsdoc-format": true, + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 140 + ], + "member-ordering": [ + true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-any": false, + "no-arg": true, + "no-bitwise": true, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": false, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-constructor-vars": false, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-eval": true, + "no-inferrable-types": false, + "no-internal-module": true, + "no-require-imports": true, + "no-shadowed-variable": true, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "no-var-requires": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single", + "avoid-escape" + ], + "radix": true, + "semicolon": true, + "switch-default": true, + "trailing-comma": [ + true, + { + "multiline": "never", + "singleline": "never" + } + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef": false, + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "use-strict": false, + "variable-name": [ + true, + "check-format", + "allow-leading-underscore", + "ban-keywords" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator" + ] + } +} diff --git a/ng2-components/ng2-alfresco-upload/demo/typings.json b/ng2-components/ng2-alfresco-upload/demo/typings.json index 39a2ebcc56..f5b42e6688 100644 --- a/ng2-components/ng2-alfresco-upload/demo/typings.json +++ b/ng2-components/ng2-alfresco-upload/demo/typings.json @@ -1,9 +1,6 @@ { - "name": "angular2-testing", - "dependencies": {}, - "devDependencies": {}, "ambientDependencies": { "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c", - "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#dd638012d63e069f2c99d06ef4dcc9616a943ee4" + "jasmine": "github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#d594ef506d1efe2fea15f8f39099d19b39436b71" } } From ede8f861ee90937e6d8bdd87e26812e6245919fd Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Mon, 23 May 2016 21:41:57 +0100 Subject: [PATCH 5/8] remove import typings --- .../ng2-alfresco-upload/demo/src/main.ts | 156 +++++++++--------- .../ng2-alfresco-upload/demo/tsconfig.json | 3 +- 2 files changed, 79 insertions(+), 80 deletions(-) diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts index fc04ad040b..49ca89683b 100644 --- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts @@ -1,79 +1,77 @@ -/// - -/*! - * @license - * Copyright 2016 Alfresco Software, Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { Component } from 'angular2/core'; -import { bootstrap } from 'angular2/platform/browser'; -import { HTTP_PROVIDERS } from 'angular2/http'; -import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; -import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload'; - - -@Component({ - selector: 'my-app', - template: ` - - -

- - - - -

- - - - -

- - -
- DRAG HERE -
-
`, - directives: [ALFRESCO_ULPOAD_COMPONENTS] -}) -export class MyDemoApp { - constructor(alfrescoSettingsService: AlfrescoSettingsService) { - alfrescoSettingsService.host = 'http://192.168.99.100:8080'; - } - - public customMethod(event: Object): void { - console.log('File uploaded'); - } -} - -bootstrap(MyDemoApp, [ - HTTP_PROVIDERS, - AlfrescoTranslationService, - AlfrescoTranslationLoader, - AlfrescoSettingsService, - UploadService -]); +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Component } from 'angular2/core'; +import { bootstrap } from 'angular2/platform/browser'; +import { HTTP_PROVIDERS } from 'angular2/http'; +import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/dist/ng2-alfresco-core'; +import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload'; + + +@Component({ + selector: 'my-app', + template: ` + + +

+ + + + +

+ + + + +

+ + +
+ DRAG HERE +
+
`, + directives: [ALFRESCO_ULPOAD_COMPONENTS] +}) +export class MyDemoApp { + constructor(alfrescoSettingsService: AlfrescoSettingsService) { + alfrescoSettingsService.host = 'http://192.168.99.100:8080'; + } + + public customMethod(event: Object): void { + console.log('File uploaded'); + } +} + +bootstrap(MyDemoApp, [ + HTTP_PROVIDERS, + AlfrescoTranslationService, + AlfrescoTranslationLoader, + AlfrescoSettingsService, + UploadService +]); diff --git a/ng2-components/ng2-alfresco-upload/demo/tsconfig.json b/ng2-components/ng2-alfresco-upload/demo/tsconfig.json index eaa102b97b..772c3a7e75 100644 --- a/ng2-components/ng2-alfresco-upload/demo/tsconfig.json +++ b/ng2-components/ng2-alfresco-upload/demo/tsconfig.json @@ -13,6 +13,7 @@ "exclude": [ "dist", "node_modules", - "typings" + "typings/main", + "typings/main.d.ts" ] } From d83270e17653c221c0cac74f3ab52dab3f8f6284 Mon Sep 17 00:00:00 2001 From: Mario Romano Date: Mon, 23 May 2016 23:28:55 +0100 Subject: [PATCH 6/8] point to dist --- ng2-components/ng2-alfresco-upload/demo/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng2-components/ng2-alfresco-upload/demo/index.html b/ng2-components/ng2-alfresco-upload/demo/index.html index 57cb4a3369..8d2a2864f0 100644 --- a/ng2-components/ng2-alfresco-upload/demo/index.html +++ b/ng2-components/ng2-alfresco-upload/demo/index.html @@ -52,7 +52,7 @@ } } }); - System.import('src/main').catch(console.log.bind(console)); + System.import('dist/main').catch(console.log.bind(console)); From 2060982ec7e76e327c9e42aaa28bfb3f6966dfc7 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Tue, 24 May 2016 00:17:21 +0100 Subject: [PATCH 7/8] #68 add page moving and input param tslint rule withespace type --- .../ng2-alfresco-datatable/tslint.json | 9 +- .../ng2-alfresco-documentlist/tslint.json | 9 +- ng2-components/ng2-alfresco-login/tslint.json | 4 +- .../ng2-alfresco-search/tslint.json | 9 +- .../upload-button.component.spec.ts | 12 +- .../ng2-alfresco-upload/tslint.json | 5 +- ng2-components/ng2-alfresco-viewer/index.html | 12 +- ng2-components/ng2-alfresco-viewer/main.ts | 4 +- .../ng2-alfresco-viewer.ts | 2 +- .../src/ng2-alfresco-viewer.component.css | 7 -- .../src/ng2-alfresco-viewer.component.ts | 67 ----------- .../src/viewer.component.css | 31 +++++ ...r.component.html => viewer.component.html} | 44 ++++++- ...onent.spec.ts => viewer.component.spec.ts} | 22 ++-- .../src/viewer.component.ts | 108 ++++++++++++++++++ .../ng2-alfresco-viewer/tslint.json | 9 +- 16 files changed, 232 insertions(+), 122 deletions(-) delete mode 100644 ng2-components/ng2-alfresco-viewer/src/ng2-alfresco-viewer.component.css delete mode 100644 ng2-components/ng2-alfresco-viewer/src/ng2-alfresco-viewer.component.ts create mode 100644 ng2-components/ng2-alfresco-viewer/src/viewer.component.css rename ng2-components/ng2-alfresco-viewer/src/{ng2-alfresco-viewer.component.html => viewer.component.html} (59%) rename ng2-components/ng2-alfresco-viewer/src/{ng2-alfresco-viewer.component.spec.ts => viewer.component.spec.ts} (60%) create mode 100644 ng2-components/ng2-alfresco-viewer/src/viewer.component.ts diff --git a/ng2-components/ng2-alfresco-datatable/tslint.json b/ng2-components/ng2-alfresco-datatable/tslint.json index e0afb6fc9c..ce1f3bcb48 100644 --- a/ng2-components/ng2-alfresco-datatable/tslint.json +++ b/ng2-components/ng2-alfresco-datatable/tslint.json @@ -110,10 +110,11 @@ ], "whitespace": [ true, - "check-branch", - "check-decl", - "check-operator", - "check-separator" + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module" ] } } diff --git a/ng2-components/ng2-alfresco-documentlist/tslint.json b/ng2-components/ng2-alfresco-documentlist/tslint.json index e0afb6fc9c..ce1f3bcb48 100644 --- a/ng2-components/ng2-alfresco-documentlist/tslint.json +++ b/ng2-components/ng2-alfresco-documentlist/tslint.json @@ -110,10 +110,11 @@ ], "whitespace": [ true, - "check-branch", - "check-decl", - "check-operator", - "check-separator" + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module" ] } } diff --git a/ng2-components/ng2-alfresco-login/tslint.json b/ng2-components/ng2-alfresco-login/tslint.json index dde69dd07e..49b228f977 100644 --- a/ng2-components/ng2-alfresco-login/tslint.json +++ b/ng2-components/ng2-alfresco-login/tslint.json @@ -113,7 +113,9 @@ "check-branch", "check-decl", "check-operator", - "check-separator" + "check-separator", + "check-type", + "check-module" ] } } diff --git a/ng2-components/ng2-alfresco-search/tslint.json b/ng2-components/ng2-alfresco-search/tslint.json index e0afb6fc9c..ce1f3bcb48 100644 --- a/ng2-components/ng2-alfresco-search/tslint.json +++ b/ng2-components/ng2-alfresco-search/tslint.json @@ -110,10 +110,11 @@ ], "whitespace": [ true, - "check-branch", - "check-decl", - "check-operator", - "check-separator" + "check-branch", + "check-operator", + "check-separator", + "check-type", + "check-module" ] } } diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index 2380925626..7f5ef40b50 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -34,7 +34,7 @@ describe('AlfrescoUploadButton', () => { }); it('should render upload-single-file button as default', - injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) .then((fixture) => { @@ -45,7 +45,7 @@ describe('AlfrescoUploadButton', () => { })); it('should render upload-multiple-file button if multipleFiles is true', - injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) .then((fixture) => { @@ -58,7 +58,7 @@ describe('AlfrescoUploadButton', () => { })); it('should render an uploadFolder button if uploadFolder is true', - injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) .then((fixture) => { @@ -70,7 +70,7 @@ describe('AlfrescoUploadButton', () => { }); })); - it('should call onFilesAdded method', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + it('should call onFilesAdded method', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) .then((fixture) => { @@ -88,8 +88,8 @@ describe('AlfrescoUploadButton', () => { }); })); - it('should render dialog box with css class show ', - injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { + it('should render dialog box with css class show', + injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent) .then((fixture) => { diff --git a/ng2-components/ng2-alfresco-upload/tslint.json b/ng2-components/ng2-alfresco-upload/tslint.json index dde69dd07e..6d41695316 100644 --- a/ng2-components/ng2-alfresco-upload/tslint.json +++ b/ng2-components/ng2-alfresco-upload/tslint.json @@ -111,9 +111,10 @@ "whitespace": [ true, "check-branch", - "check-decl", "check-operator", - "check-separator" + "check-separator", + "check-type", + "check-module" ] } } diff --git a/ng2-components/ng2-alfresco-viewer/index.html b/ng2-components/ng2-alfresco-viewer/index.html index beca5123ac..a213920f4e 100644 --- a/ng2-components/ng2-alfresco-viewer/index.html +++ b/ng2-components/ng2-alfresco-viewer/index.html @@ -21,10 +21,7 @@ - - +