fix dependencies and core

This commit is contained in:
Mario Romano 2016-05-21 04:25:44 +01:00
parent 5c8e37073f
commit c13d6a7fc3
70 changed files with 840 additions and 288 deletions

View File

@ -18,14 +18,14 @@
import { Component } from 'angular2/core'; import { Component } from 'angular2/core';
import { ControlGroup, FormBuilder, Validators } from 'angular2/common'; import { ControlGroup, FormBuilder, Validators } from 'angular2/common';
import { Router, RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router'; import { Router, RouteConfig, ROUTER_DIRECTIVES } from 'angular2/router';
import { MDL } from 'ng2-alfresco-core/material'; import { MDL } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { FilesComponent } from './components/files/files.component'; import { FilesComponent } from './components/files/files.component';
import { AlfrescoLoginComponent, AlfrescoAuthenticationService } from 'ng2-alfresco-login/ng2-alfresco-login'; import { AlfrescoLoginComponent, AlfrescoAuthenticationService } from 'ng2-alfresco-login/dist/ng2-alfresco-login';
import { AuthRouterOutlet } from './components/router/AuthRouterOutlet'; import { AuthRouterOutlet } from './components/router/AuthRouterOutlet';
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { UploadButtonComponent } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { UploadButtonComponent } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
import { DataTableDemoComponent } from './components/datatable/datatable-demo.component'; import { DataTableDemoComponent } from './components/datatable/datatable-demo.component';
import { AlfrescoSearchComponent } from 'ng2-alfresco-search/ng2-alfresco-search'; import { AlfrescoSearchComponent } from 'ng2-alfresco-search/dist/ng2-alfresco-search';
declare var document: any; declare var document: any;

View File

@ -16,14 +16,14 @@
*/ */
import { Component } from 'angular2/core'; import { Component } from 'angular2/core';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { import {
ALFRESCO_DATATABLE_DIRECTIVES, ALFRESCO_DATATABLE_DIRECTIVES,
ObjectDataTableAdapter, ObjectDataTableAdapter,
DataSorting, DataSorting,
ObjectDataRow, ObjectDataRow,
ObjectDataColumn ObjectDataColumn
} from 'ng2-alfresco-datatable/ng2-alfresco-datatable'; } from 'ng2-alfresco-datatable/dist/ng2-alfresco-datatable';
declare let __moduleName: string; declare let __moduleName: string;

View File

@ -20,10 +20,10 @@ import {
DOCUMENT_LIST_DIRECTIVES, DOCUMENT_LIST_DIRECTIVES,
DOCUMENT_LIST_PROVIDERS, DOCUMENT_LIST_PROVIDERS,
DocumentActionsService DocumentActionsService
} from 'ng2-alfresco-documentlist/ng2-alfresco-documentlist'; } from 'ng2-alfresco-documentlist/dist/ng2-alfresco-documentlist';
import { MDL } from 'ng2-alfresco-core/material'; import { MDL } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { ALFRESCO_ULPOAD_COMPONENT } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { ALFRESCO_ULPOAD_COMPONENTS } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string; declare let __moduleName: string;
@ -31,7 +31,7 @@ declare let __moduleName: string;
moduleId: __moduleName, moduleId: __moduleName,
selector: 'files-component', selector: 'files-component',
templateUrl: './files.component.html', templateUrl: './files.component.html',
directives: [DOCUMENT_LIST_DIRECTIVES, MDL, ALFRESCO_ULPOAD_COMPONENT], directives: [DOCUMENT_LIST_DIRECTIVES, MDL, ALFRESCO_ULPOAD_COMPONENTS],
providers: [DOCUMENT_LIST_PROVIDERS], providers: [DOCUMENT_LIST_PROVIDERS],
pipes: [AlfrescoPipeTranslate] pipes: [AlfrescoPipeTranslate]
}) })
@ -58,7 +58,7 @@ export class FilesComponent {
alert('Custom folder action for ' + event.value.displayName); alert('Custom folder action for ' + event.value.displayName);
} }
refreshDirectyory(event: Object) { refreshDirectyory(event: any) {
this.absolutePath = event.value; this.absolutePath = event.value;
this.relativePath = this.getRelativeDirectory(this.absolutePath); this.relativePath = this.getRelativeDirectory(this.absolutePath);
} }

View File

@ -16,7 +16,7 @@
*/ */
import { ElementRef, DynamicComponentLoader, Directive, Attribute } from 'angular2/core'; import { ElementRef, DynamicComponentLoader, Directive, Attribute } from 'angular2/core';
import { Router, RouterOutlet, ComponentInstruction } from 'angular2/router'; import { Router, RouterOutlet, ComponentInstruction } from 'angular2/router';
import { AlfrescoAuthenticationService } from 'ng2-alfresco-login/ng2-alfresco-login'; import { AlfrescoAuthenticationService } from 'ng2-alfresco-login/dist/ng2-alfresco-login';
@Directive({selector: 'auth-router-outlet'}) @Directive({selector: 'auth-router-outlet'})
export class AuthRouterOutlet extends RouterOutlet { export class AuthRouterOutlet extends RouterOutlet {

View File

@ -19,9 +19,9 @@ import { bootstrap } from 'angular2/platform/browser';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { ROUTER_PROVIDERS } from 'angular2/router'; import { ROUTER_PROVIDERS } from 'angular2/router';
import { HTTP_PROVIDERS } from 'angular2/http'; import { HTTP_PROVIDERS } from 'angular2/http';
import { ALFRESCO_AUTHENTICATION } from 'ng2-alfresco-login/ng2-alfresco-login'; import { ALFRESCO_AUTHENTICATION } from 'ng2-alfresco-login/dist/ng2-alfresco-login';
import { ALFRESCO_CORE_PROVIDERS, AlfrescoTranslationService } from 'ng2-alfresco-core/services'; import { ALFRESCO_CORE_PROVIDERS, AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
bootstrap(AppComponent, [ bootstrap(AppComponent, [
ROUTER_PROVIDERS, ROUTER_PROVIDERS,

View File

@ -19,13 +19,12 @@
// map tells the System loader where to look for things // map tells the System loader where to look for things
var map = { var map = {
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist', 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core',
'ng2-alfresco-datatable': 'node_modules/ng2-alfresco-datatable/dist', 'ng2-alfresco-datatable': 'node_modules/ng2-alfresco-datatable',
'ng2-alfresco-documentlist': 'node_modules/ng2-alfresco-documentlist/dist', 'ng2-alfresco-documentlist': 'node_modules/ng2-alfresco-documentlist',
'ng2-alfresco-login': 'node_modules/ng2-alfresco-login/dist', 'ng2-alfresco-login': 'node_modules/ng2-alfresco-login',
'ng2-alfresco-search': 'node_modules/ng2-alfresco-search/dist', 'ng2-alfresco-search': 'node_modules/ng2-alfresco-search',
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload/dist', 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload',
'ng2-translate': 'node_modules/ng2-translate',
'rxjs': 'node_modules/rxjs' 'rxjs': 'node_modules/rxjs'
}; };
@ -41,7 +40,6 @@
'ng2-alfresco-login': {defaultExtension: 'js'}, 'ng2-alfresco-login': {defaultExtension: 'js'},
'ng2-alfresco-search': {defaultExtension: 'js'}, 'ng2-alfresco-search': {defaultExtension: 'js'},
'ng2-alfresco-upload': {defaultExtension: 'js'}, 'ng2-alfresco-upload': {defaultExtension: 'js'},
'ng2-translate': {defaultExtension: 'js'},
'rxjs': {defaultExtension: 'js'} 'rxjs': {defaultExtension: 'js'}
}; };

View File

@ -8,17 +8,8 @@ dist
src/**/*.js src/**/*.js
src/**/*.js.map src/**/*.js.map
src/**/*.d.ts src/**/*.d.ts
material.js
material.js.map
material/**/*.js
material/**/*.js.map
services.js
services.js.map
services/**/*.js
services/**/*.js.map
demo/**/*.js demo/**/*.js
demo/**/*.js.map demo/**/*.js.map
demo/**/*.d.ts demo/**/*.d.ts
ng2-alfresco-core.js
ng2-alfresco-core.js.map

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-upload.ts /.editorconfig
/ng2-alfresco-upload.d.ts /.travis.yml
/ng2-alfresco-upload.js /*.js
/ng2-alfresco-upload.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -26,8 +26,7 @@ module.exports = function (config) {
{pattern: 'dist/**/*.css', included: true, served: true, watched: true}, {pattern: 'dist/**/*.css', included: true, served: true, watched: true},
// paths to support debugging with source maps in dev tools // paths to support debugging with source maps in dev tools
{pattern: 'services/**/*.ts', included: false, watched: false}, {pattern: 'src/**/*.ts', included: false, watched: false},
{pattern: 'material/**/*.ts', included: false, watched: false},
{pattern: 'dist/**/*.js.map', included: false, watched: false} {pattern: 'dist/**/*.js.map', included: false, watched: false}
], ],
@ -75,6 +74,6 @@ module.exports = function (config) {
] ]
}, },
singleRun: false singleRun: true
}) })
}; };

View File

@ -1,18 +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 * from './material/MaterialDesignLiteUpgradeElement';

View File

@ -16,18 +16,18 @@
*/ */
import {AlfrescoSettingsService} from './services/AlfrescoSettingsService.service'; import {AlfrescoSettingsService} from './src/services/AlfrescoSettingsService.service';
import {AlfrescoTranslationLoader} from './services/AlfrescoTranslationLoader.service'; import {AlfrescoTranslationLoader} from './src/services/AlfrescoTranslationLoader.service';
import {AlfrescoTranslationService} from './services/AlfrescoTranslationService.service'; import {AlfrescoTranslationService} from './src/services/AlfrescoTranslationService.service';
import {AlfrescoPipeTranslate} from './services/AlfrescoPipeTranslate.service'; import {AlfrescoPipeTranslate} from './src/services/AlfrescoPipeTranslate.service';
export * from './services/AlfrescoSettingsService.service'; export * from './src/services/AlfrescoSettingsService.service';
export * from './services/AlfrescoTranslationLoader.service'; export * from './src/services/AlfrescoTranslationLoader.service';
export * from './services/AlfrescoTranslationService.service'; export * from './src/services/AlfrescoTranslationService.service';
export * from './services/AlfrescoPipeTranslate.service'; export * from './src/services/AlfrescoPipeTranslate.service';
export * from './src/material/MaterialDesignLiteUpgradeElement';
export default { export default {
directives: [],
providers: [ providers: [
AlfrescoSettingsService, AlfrescoSettingsService,
AlfrescoTranslationLoader, AlfrescoTranslationLoader,
@ -42,3 +42,4 @@ export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoTranslationService, AlfrescoTranslationService,
AlfrescoPipeTranslate AlfrescoPipeTranslate
]; ];

View File

@ -1,15 +1,14 @@
{ {
"name": "ng2-alfresco-core", "name": "ng2-alfresco-core",
"description": "Alfresco Angular 2 Components core", "description": "Alfresco Angular 2 Components core",
"version": "0.1.13", "version": "0.1.17",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",
"start": "npm run test && http-server -c-1 -o -p 8875 .", "start": "npm run test && http-server -c-1 -o -p 8875 .",
"build": "npm run tslint && typings install && rm -rf dist && tsc && npm run copytemplates && license-check", "build": "npm run tslint && typings install && rm -rf dist && tsc && npm run copytemplates && license-check",
"tslint": "npm run tslint-service && npm run tslint-material && npm run tslint-root", "tslint": "npm run tslint-src && npm run tslint-root",
"tslint-service": "tslint -c tslint.json services/**/*.ts", "tslint-src": "tslint -c tslint.json src/**/*.ts",
"tslint-material": "tslint -c tslint.json material/**/*.ts",
"tslint-root": "tslint -c tslint.json *.ts", "tslint-root": "tslint -c tslint.json *.ts",
"copytemplates": "npm run copy-html && npm run copy-css && npm run copy-i18n", "copytemplates": "npm run copy-html && npm run copy-css && npm run copy-i18n",
"copy-html": "copyfiles './src/**/*.html' dist", "copy-html": "copyfiles './src/**/*.html' dist",
@ -51,7 +50,6 @@
"angular2": "2.0.0-beta.15", "angular2": "2.0.0-beta.15",
"es6-module-loader": "^0.17.8", "es6-module-loader": "^0.17.8",
"es6-shim": "^0.35.0", "es6-shim": "^0.35.0",
"ng2-translate": "^1.11.3",
"reflect-metadata": "0.1.2", "reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2", "rxjs": "5.0.0-beta.2",
"systemjs": "0.19.26", "systemjs": "0.19.26",

View File

@ -1,32 +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.
*/
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 extends TranslatePipe {
constructor(translate: AlfrescoTranslationService, _ref: ChangeDetectorRef) {
super(translate, _ref);
}
}

View File

@ -1,45 +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.
*/
import { Injectable, Optional } from 'angular2/core';
import { Http } from 'angular2/http';
import { MissingTranslationHandler, TranslateService } from 'ng2-translate/ng2-translate';
import { AlfrescoTranslationLoader } from './AlfrescoTranslationLoader.service';
@Injectable()
export class AlfrescoTranslationService extends TranslateService {
userLang: string = 'en' ;
currentLoader: AlfrescoTranslationLoader;
constructor(http: Http, currentLoader: AlfrescoTranslationLoader, @Optional() missingTranslationHandler: MissingTranslationHandler) {
super(http, currentLoader, missingTranslationHandler);
}
translationInit(name: string = ''): void {
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
this.userLang = userLang;
this.setDefaultLang(this.userLang);
this.addComponent(name);
this.use(this.userLang);
}
addComponent(name: string) {
this.currentLoader.addComponentList(name);
this.getTranslation(this.userLang);
}
}

View File

@ -0,0 +1,166 @@
/*!
* @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 { PipeTransform, Pipe, Injectable, EventEmitter, OnDestroy, ChangeDetectorRef } from 'angular2/core';
import { AlfrescoTranslationService, LangChangeEvent } from './AlfrescoTranslationService.service';
import { isPresent, isArray } from 'angular2/src/facade/lang';
@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<LangChangeEvent>;
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();
}
}

View File

@ -18,7 +18,7 @@
import { Injectable } from 'angular2/core'; import { Injectable } from 'angular2/core';
import { Response, Http } from 'angular2/http'; import { Response, Http } from 'angular2/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { TranslateLoader } from 'ng2-translate/ng2-translate'; import { TranslateLoader } from './AlfrescoTranslationService.service';
@Injectable() @Injectable()
export class AlfrescoTranslationLoader implements TranslateLoader { export class AlfrescoTranslationLoader implements TranslateLoader {

View File

@ -0,0 +1,348 @@
/*!
* @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 { Injectable, Optional, EventEmitter } from 'angular2/core';
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<any>;
}
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<any> {
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;
/**
* An EventEmitter to listen to lang changes events
* onLangChange.subscribe((params: LangChangeEvent) => {
* // do something
* });
* @type {ng.EventEmitter<LangChangeEvent>}
*/
public onLangChange: EventEmitter<LangChangeEvent> = new EventEmitter<LangChangeEvent>();
private pending: any;
private translations: any = {};
private defaultLang: string;
private langs: Array<string>;
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) {
}
translationInit(name: string = ''): void {
let userLang = navigator.language.split('-')[0]; // use navigator lang if available
userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en';
this.userLang = userLang;
this.setDefaultLang(this.userLang);
this.addComponent(name);
this.use(this.userLang);
}
addComponent(name: string) {
this.currentLoader.addComponentList(name);
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<any> {
let pending: Observable<any>;
// 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<any> {
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<string> {
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<string>;
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<string>) => {
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<string>, interpolateParams?: Object): Observable<string|any> {
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<string>) => {
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<string>, 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<any>}
*/
public reloadLang(lang: string): Observable<any> {
this.resetLang(lang);
return this.getTranslation(lang);
}
/**
* Deletes inner translation
* @param lang
*/
public resetLang(lang: string): void {
this.translations[lang] = undefined;
}
}

View File

@ -0,0 +1,65 @@
/*!
* @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;
}
}

View File

@ -21,6 +21,7 @@
"demo", "demo",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-datatable.ts /.editorconfig
/ng2-alfresco-datatable.d.ts /.travis.yml
/ng2-alfresco-datatable.js /*.js
/ng2-alfresco-datatable.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -13,10 +13,17 @@ System.config({
defaultExtension: 'js', defaultExtension: 'js',
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
},
'ng2-alfresco-core/dist': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
} }
}, },
map: { map: {
'ng2-alfresco-core': '/base/dist/node_modules/ng2-alfresco-core' 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
'rxjs': '/base/node_modules/rxjs'
} }
}); });

View File

@ -11,11 +11,12 @@ module.exports = function (config) {
// paths loaded by Karma // paths loaded by Karma
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true}, {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false, served: true},
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
{pattern: 'node_modules/alfresco-core-rest-api/bundle.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: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-datatable", "name": "ng2-alfresco-datatable",
"description": "Alfresco Angular2 DataTable Component", "description": "Alfresco Angular2 DataTable Component",
"version": "0.1.4", "version": "0.1.5",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@ -12,8 +12,10 @@
}, },
"exclude": [ "exclude": [
"demo", "demo",
"dist",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-documentlist.ts /.editorconfig
/ng2-alfresco-documentlist.d.ts /.travis.yml
/ng2-alfresco-documentlist.js /*.js
/ng2-alfresco-documentlist.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -13,10 +13,17 @@ System.config({
defaultExtension: 'js', defaultExtension: 'js',
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
},
'ng2-alfresco-core/dist': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
} }
}, },
map: { map: {
'ng2-alfresco-core': '/base/dist/node_modules/ng2-alfresco-core' 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
'rxjs': '/base/node_modules/rxjs'
} }
}); });

View File

@ -11,11 +11,12 @@ module.exports = function (config) {
// paths loaded by Karma // paths loaded by Karma
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true}, {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false, served: true},
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
{pattern: 'node_modules/alfresco-core-rest-api/bundle.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: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-documentlist", "name": "ng2-alfresco-documentlist",
"description": "Alfresco Angular2 Document List Component", "description": "Alfresco Angular2 Document List Component",
"version": "0.1.2", "version": "0.1.3",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@ -18,7 +18,7 @@
import {Http} from 'angular2/http'; import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {AlfrescoService} from '../../src/services/alfresco.service'; import {AlfrescoService} from '../../src/services/alfresco.service';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/services'; import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
export class AlfrescoServiceMock extends AlfrescoService { export class AlfrescoServiceMock extends AlfrescoService {

View File

@ -19,7 +19,7 @@ import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http'; import { Http, Response } from 'angular2/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model'; import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any; declare let AlfrescoApi: any;

View File

@ -14,6 +14,7 @@
"demo", "demo",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-upload.ts /.editorconfig
/ng2-alfresco-upload.d.ts /.travis.yml
/ng2-alfresco-upload.js /*.js
/ng2-alfresco-upload.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -12,6 +12,7 @@
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",
"typings" "typings",
"dist"
] ]
} }

View File

@ -14,14 +14,16 @@ System.config({
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
}, },
'ng2-translate': { 'ng2-alfresco-core/dist': {
defaultExtension: 'js', defaultExtension: 'js'
format: 'register' },
'rxjs': {
defaultExtension: 'js'
} }
}, },
map: { map: {
'ng2-translate': '/base/node_modules/ng2-translate/bundles', 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
'ng2-alfresco-core': '/base/dist/node_modules/ng2-alfresco-core' 'rxjs': '/base/node_modules/rxjs'
} }
}); });

View File

@ -11,13 +11,13 @@ module.exports = function (config) {
// paths loaded by Karma // paths loaded by Karma
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: false}, { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false, served: true },
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false}, {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/alfresco-core-rest-api/bundle.js', included: true, watched: false},
{pattern: 'node_modules/ng2-translate/bundles/ng2-translate.js', included: true, watched: false}, {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-login", "name": "ng2-alfresco-login",
"description": "Alfresco Angular2 Login Component", "description": "Alfresco Angular2 Login Component",
"version": "0.1.4", "version": "0.1.5",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@ -17,8 +17,11 @@
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { EventEmitter } from 'angular2/core'; import { EventEmitter } from 'angular2/core';
import { LangChangeEvent } from 'ng2-translate/ng2-translate';
export interface LangChangeEvent {
lang: string;
translations: any;
}
export class TranslationMock { export class TranslationMock {

View File

@ -31,7 +31,7 @@ import { provide } from 'angular2/core';
import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/router'; import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/router';
import { RootRouter } from 'angular2/src/router/router'; import { RootRouter } from 'angular2/src/router/router';
import { SpyLocation } from 'angular2/src/mock/location_mock'; import { SpyLocation } from 'angular2/src/mock/location_mock';
import { TranslateService } from 'ng2-translate/ng2-translate'; import { AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { AlfrescoLoginComponent } from './alfresco-login.component'; import { AlfrescoLoginComponent } from './alfresco-login.component';
import { AuthenticationMock } from './../assets/authentication.service.mock'; import { AuthenticationMock } from './../assets/authentication.service.mock';
import { TranslationMock } from './../assets/translation.service.mock'; import { TranslationMock } from './../assets/translation.service.mock';
@ -50,7 +50,7 @@ describe('AlfrescoLogin', () => {
provide(Location, {useClass: SpyLocation}), provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}), provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}),
provide(Router, {useClass: RootRouter}), provide(Router, {useClass: RootRouter}),
provide(TranslateService, {useClass: TranslationMock}) provide(AlfrescoTranslationService, {useClass: TranslationMock})
]; ];
}); });

View File

@ -19,7 +19,7 @@ import { Component, Output, EventEmitter } from 'angular2/core';
import { Router, ROUTER_DIRECTIVES } from 'angular2/router'; import { Router, ROUTER_DIRECTIVES } from 'angular2/router';
import { FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from 'angular2/common'; import { FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from 'angular2/common';
import { AlfrescoAuthenticationService } from './../services/alfresco-authentication.service'; import { AlfrescoAuthenticationService } from './../services/alfresco-authentication.service';
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let componentHandler: any; declare let componentHandler: any;
declare let __moduleName: string; declare let __moduleName: string;

View File

@ -21,6 +21,7 @@
"demo", "demo",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-search.ts /.editorconfig
/ng2-alfresco-search.d.ts /.travis.yml
/ng2-alfresco-search.js /*.js
/ng2-alfresco-search.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -13,10 +13,13 @@ System.config({
defaultExtension: 'js', defaultExtension: 'js',
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
},
'ng2-alfresco-core/dist': {
defaultExtension: 'js'
} }
}, },
map: { map: {
'ng2-alfresco-core': '/base/dist/node_modules/ng2-alfresco-core' 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist'
} }
}); });

View File

@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-search", "name": "ng2-alfresco-search",
"description": "Alfresco Angular2 Search Component", "description": "Alfresco Angular2 Search Component",
"version": "0.1.2", "version": "0.1.3",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@ -18,7 +18,7 @@
import {Http} from 'angular2/http'; import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable'; import {Observable} from 'rxjs/Observable';
import {AlfrescoSettingsService} from 'ng2-alfresco-core/services'; import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import {AlfrescoService} from './../../src/services/alfresco.service'; import {AlfrescoService} from './../../src/services/alfresco.service';
export class AlfrescoServiceMock extends AlfrescoService { export class AlfrescoServiceMock extends AlfrescoService {

View File

@ -19,7 +19,7 @@ import { Injectable } from 'angular2/core';
import { Http, Response } from 'angular2/http'; import { Http, Response } from 'angular2/http';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any; declare let AlfrescoApi: any;

View File

@ -13,6 +13,7 @@
"exclude": [ "exclude": [
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -7,8 +7,12 @@ demo/
node_modules node_modules
typings/ typings/
src/ src/
fonts/
/ng2-alfresco-upload.ts /.editorconfig
/ng2-alfresco-upload.d.ts /.travis.yml
/ng2-alfresco-upload.js /*.js
/ng2-alfresco-upload.js.map /*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -46,36 +46,36 @@ Make sure your systemjs.config has the following configuration:
```javascript ```javascript
System.config({ System.config({
defaultJSExtensions: true, defaultJSExtensions: true,
map: { map: {
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist', 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist',
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload/dist', 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload',
'ng2-translate': 'node_modules/ng2-translate', 'ng2-translate': 'node_modules/ng2-translate',
'rxjs': 'node_modules/rxjs', 'rxjs': 'node_modules/rxjs',
'angular2' : 'node_modules/angular2', 'angular2' : 'node_modules/angular2',
'app': 'dist/src' 'app': 'dist/src'
},
packages: {
'app': {
defaultExtension: 'js'
}, },
'ng2-alfresco-core': { packages: {
defaultExtension: 'js' 'app': {
}, defaultExtension: 'js'
'ng2-alfresco-upload': { },
defaultExtension: 'js' 'ng2-alfresco-core': {
}, defaultExtension: 'js'
'ng2-translate': { },
defaultExtension: 'js' 'ng2-alfresco-upload': {
}, defaultExtension: 'js'
'rxjs': { },
defaultExtension: 'js' 'ng2-translate': {
}, defaultExtension: 'js'
'angular2': { },
defaultExtension: 'js' 'rxjs': {
defaultExtension: 'js'
},
'angular2': {
defaultExtension: 'js'
}
} }
} });
});
``` ```
#### Basic usage #### Basic usage
@ -98,7 +98,7 @@ import { Component } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser'; import { bootstrap } from 'angular2/platform/browser';
import { HTTP_PROVIDERS } from 'angular2/http'; import { HTTP_PROVIDERS } from 'angular2/http';
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
@Component({ @Component({
@ -157,7 +157,7 @@ import { Component } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser'; import { bootstrap } from 'angular2/platform/browser';
import { HTTP_PROVIDERS } from 'angular2/http'; import { HTTP_PROVIDERS } from 'angular2/http';
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services';
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
@Component({ @Component({

View File

@ -27,8 +27,8 @@
System.config({ System.config({
defaultJSExtensions: true, defaultJSExtensions: true,
map: { map: {
'ng2-alfresco-core': 'node_modules/ng2-alfresco-core/dist', 'ng2-alfresco-core': 'node_modules/ng2-alfresco-core',
'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload/dist', 'ng2-alfresco-upload': 'node_modules/ng2-alfresco-upload',
'ng2-translate': 'node_modules/ng2-translate', 'ng2-translate': 'node_modules/ng2-translate',
'rxjs': 'node_modules/rxjs', 'rxjs': 'node_modules/rxjs',
'angular2' : 'node_modules/angular2', 'angular2' : 'node_modules/angular2',
@ -56,7 +56,7 @@
} }
}); });
System.import('dist/src/my-app').catch(console.log.bind(console)); System.import('dist/my-app').catch(console.log.bind(console));
</script> </script>
</head> </head>

View File

@ -20,8 +20,8 @@
import { Component } from 'angular2/core'; import { Component } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser'; import { bootstrap } from 'angular2/platform/browser';
import { HTTP_PROVIDERS } from 'angular2/http'; import { HTTP_PROVIDERS } from 'angular2/http';
import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService, AlfrescoTranslationService, AlfrescoTranslationLoader } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng2-alfresco-upload'; import { ALFRESCO_ULPOAD_COMPONENTS, UploadService } from 'ng2-alfresco-upload/dist/ng2-alfresco-upload';
@Component({ @Component({
@ -58,7 +58,7 @@ import { ALFRESCO_ULPOAD_COMPONENT, UploadService } from 'ng2-alfresco-upload/ng
DRAG HERE DRAG HERE
</div> </div>
</alfresco-upload-drag-area>`, </alfresco-upload-drag-area>`,
directives: [ALFRESCO_ULPOAD_COMPONENT] directives: [ALFRESCO_ULPOAD_COMPONENTS]
}) })
export class MyDemoApp { export class MyDemoApp {
constructor(alfrescoSettingsService: AlfrescoSettingsService) { constructor(alfrescoSettingsService: AlfrescoSettingsService) {

View File

@ -12,6 +12,7 @@
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",
"typings" "typings",
"dist"
] ]
} }

View File

@ -14,14 +14,16 @@ System.config({
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
}, },
'ng2-translate': { 'ng2-alfresco-core/dist': {
defaultExtension: 'js', defaultExtension: 'js'
format: 'register' },
'rxjs': {
defaultExtension: 'js'
} }
}, },
map: { map: {
'ng2-translate': '/base/node_modules/ng2-translate/bundles', 'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
'ng2-alfresco-core': '/base/dist/node_modules/ng2-alfresco-core' 'rxjs': '/base/node_modules/rxjs'
} }
}); });
@ -33,14 +35,13 @@ System.import('angular2/src/platform/browser/browser_adapter')
__karma__.start(); __karma__.start();
}, },
function(error) { function(error) {
console.log(error);
__karma__.error(error.stack || error); __karma__.error(error.stack || error);
} }
); );
function createPathRecords(pathsMapping, appPath) { function createPathRecords(pathsMapping, appPath) {
// creates local module name mapping to global path with karma's fingerprint in path, e.g.: // creates local module name mapping to global path with karma's fingerprint in path, e.g.:
// './vg-player/vg-player':
// '/base/dist/vg-player/vg-player.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
var moduleName = './' + resolveKeyPathForMapping('base/dist/', appPath); var moduleName = './' + resolveKeyPathForMapping('base/dist/', appPath);
moduleName = moduleName.replace(/\.js$/, ''); moduleName = moduleName.replace(/\.js$/, '');
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
@ -60,7 +61,6 @@ function resolveTestFiles() {
.filter(onlySpecFiles) .filter(onlySpecFiles)
.map(function(moduleName) { .map(function(moduleName) {
// loads all spec files via their global module names (e.g. // loads all spec files via their global module names (e.g.
// 'base/dist/vg-player/vg-player.spec')
return System.import(moduleName); return System.import(moduleName);
}); });
} }

View File

@ -11,13 +11,13 @@ module.exports = function (config) {
// paths loaded by Karma // paths loaded by Karma
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: false}, {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false, served: true},
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, served: true, watched: false}, {pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, served: true, watched: false}, {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, served: true, watched: false}, {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, served: true, watched: false},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false}, {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/alfresco-core-rest-api/bundle.js', included: true, watched: false},
{pattern: 'node_modules/ng2-translate/bundles/ng2-translate.js', included: true, watched: false}, {pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true},
@ -41,7 +41,7 @@ module.exports = function (config) {
// level of logging // level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO, logLevel: config.LOG_DEBUG,
colors: true, colors: true,
@ -76,6 +76,6 @@ module.exports = function (config) {
] ]
}, },
singleRun: false singleRun: true
}) })
}; };

View File

@ -18,6 +18,7 @@
import { UploadDragAreaComponent } from './src/components/upload-drag-area.component'; import { UploadDragAreaComponent } from './src/components/upload-drag-area.component';
import { FileDraggableDirective } from './src/directives/file-draggable.directive'; import { FileDraggableDirective } from './src/directives/file-draggable.directive';
import { UploadButtonComponent } from './src/components/upload-button.component'; import { UploadButtonComponent } from './src/components/upload-button.component';
import { UploadService } from './src/services/upload.service';
/** /**
* ng2-alfresco-upload, provide components to upload files to alfresco repository. * ng2-alfresco-upload, provide components to upload files to alfresco repository.
@ -41,12 +42,20 @@ export * from './src/services/upload.service';
export * from './src/directives/file-draggable.directive'; export * from './src/directives/file-draggable.directive';
export default { export default {
component: [UploadDragAreaComponent, UploadButtonComponent], components: [UploadDragAreaComponent, UploadButtonComponent],
directives: [FileDraggableDirective] providers: [FileDraggableDirective],
directives: [UploadService]
}; };
export const ALFRESCO_ULPOAD_COMPONENT: [any] = [ export const ALFRESCO_ULPOAD_COMPONENTS: [any] = [
UploadDragAreaComponent, UploadDragAreaComponent,
UploadButtonComponent, UploadButtonComponent
FileDraggableDirective ];
export const ALFRESCO_ULPOAD_DIRECTIVES: [any] = [
FileDraggableDirective
];
export const ALFRESCO_ULPOAD_SERVICES: [any] = [
UploadService
]; ];

View File

@ -1,7 +1,7 @@
{ {
"name": "ng2-alfresco-upload", "name": "ng2-alfresco-upload",
"description": "Alfresco Angular2 Upload Component", "description": "Alfresco Angular2 Upload Component",
"version": "0.1.5", "version": "0.1.8",
"author": "Alfresco Software, Ltd.", "author": "Alfresco Software, Ltd.",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",

View File

@ -17,7 +17,11 @@
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { EventEmitter } from 'angular2/core'; import { EventEmitter } from 'angular2/core';
import { LangChangeEvent } from 'ng2-translate/ng2-translate';
export interface LangChangeEvent {
lang: string;
translations: any;
}
export class TranslationMock { export class TranslationMock {

View File

@ -18,7 +18,7 @@
import { Component, ElementRef, Input } from 'angular2/core'; import { Component, ElementRef, Input } from 'angular2/core';
import { FileModel } from '../models/file.model'; import { FileModel } from '../models/file.model';
import { FileUploadingListComponent } from './file-uploading-list.component'; import { FileUploadingListComponent } from './file-uploading-list.component';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string; declare let __moduleName: string;

View File

@ -18,7 +18,7 @@
import { Component, ElementRef, Input } from 'angular2/core'; import { Component, ElementRef, Input } from 'angular2/core';
import { FileModel } from '../models/file.model'; import { FileModel } from '../models/file.model';
import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let __moduleName: string; declare let __moduleName: string;

View File

@ -20,7 +20,7 @@ import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS } f
import { it, describe, expect, injectAsync, beforeEachProviders, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing'; import { it, describe, expect, injectAsync, beforeEachProviders, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing';
import { provide } from 'angular2/core'; import { provide } from 'angular2/core';
import { UploadButtonComponent } from './upload-button.component'; import { UploadButtonComponent } from './upload-button.component';
import { TranslateService } from 'ng2-translate/ng2-translate'; import { AlfrescoTranslationService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import { TranslationMock } from '../assets/translation.service.mock'; import { TranslationMock } from '../assets/translation.service.mock';
describe('AlfrescoUploadButton', () => { describe('AlfrescoUploadButton', () => {
@ -29,7 +29,7 @@ describe('AlfrescoUploadButton', () => {
beforeEachProviders(() => { beforeEachProviders(() => {
return [ return [
provide(TranslateService, {useClass: TranslationMock}) provide(AlfrescoTranslationService, {useClass: TranslationMock})
]; ];
}); });

View File

@ -20,7 +20,7 @@ import { Component, ViewChild, ElementRef, Input, Output, EventEmitter } from 'a
import { UploadService } from '../services/upload.service'; import { UploadService } from '../services/upload.service';
import { FileModel } from '../models/file.model'; import { FileModel } from '../models/file.model';
import { FileUploadingDialogComponent } from './file-uploading-dialog.component'; import { FileUploadingDialogComponent } from './file-uploading-dialog.component';
import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/services'; import { AlfrescoTranslationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
import 'rxjs/Rx'; import 'rxjs/Rx';
declare let componentHandler: any; declare let componentHandler: any;

View File

@ -20,7 +20,7 @@ import { FileModel } from '../models/file.model';
import { EventEmitter, Injectable } from 'angular2/core'; import { EventEmitter, Injectable } from 'angular2/core';
import { Observable } from 'rxjs/Observable'; import { Observable } from 'rxjs/Observable';
import { Response } from 'angular2/http'; import { Response } from 'angular2/http';
import { AlfrescoSettingsService } from 'ng2-alfresco-core/services'; import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
declare let AlfrescoApi: any; declare let AlfrescoApi: any;

View File

@ -21,6 +21,7 @@
"demo", "demo",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }

View File

@ -0,0 +1,18 @@
npm-debug.log
.idea
assets/
coverage/
demo/
node_modules
typings/
src/
fonts/
/.editorconfig
/.travis.yml
/*.js
/*.json
/*.ts
/*.js.map
/.npmignore

View File

@ -12,6 +12,7 @@
}, },
"exclude": [ "exclude": [
"node_modules", "node_modules",
"typings" "typings",
"dist"
] ]
} }

View File

@ -13,14 +13,7 @@ System.config({
defaultExtension: 'js', defaultExtension: 'js',
format: 'register', format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {}) map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
},
'ng2-translate': {
defaultExtension: 'js',
format: 'register'
} }
},
map: {
'ng2-translate': '/base/node_modules/ng2-translate/bundles'
} }
}); });

View File

@ -17,7 +17,6 @@ module.exports = function (config) {
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: false}, {pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false}, {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/alfresco-core-rest-api/bundle.js', included: true, watched: false},
{pattern: 'node_modules/ng2-translate/bundles/ng2-translate.js', included: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true},

View File

@ -1,12 +1,12 @@
{ {
"keywords": [ "keywords": [
"viewer", "viewer",
"pdf", "pdf",
"alfresco-component" "alfresco-component"
], ],
"name": "ng2-alfresco-viewer", "name": "ng2-alfresco-viewer",
"description": "Alfresco documents viewer", "description": "Alfresco documents viewer",
"version": "0.1.1", "version": "0.1.2",
"author": "Eugenio Romano", "author": "Eugenio Romano",
"scripts": { "scripts": {
"typings": "typings install", "typings": "typings install",
@ -42,8 +42,7 @@
"pdfjs-dist": "^1.5.258", "pdfjs-dist": "^1.5.258",
"reflect-metadata": "0.1.2", "reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2", "rxjs": "5.0.0-beta.2",
"zone.js": "^0.6.12", "zone.js": "^0.6.12"
"ng2-translate": "^1.11.2"
}, },
"peerDependencies": { "peerDependencies": {
"angular2": "2.0.0-beta.15" "angular2": "2.0.0-beta.15"

View File

@ -21,6 +21,7 @@
"demo", "demo",
"node_modules", "node_modules",
"typings/main", "typings/main",
"typings/main.d.ts" "typings/main.d.ts",
"dist"
] ]
} }