#17 Refactoring and renaming

This commit is contained in:
mauriziovitale84
2016-04-28 14:08:05 +01:00
parent 464688918d
commit fb20334426
26 changed files with 200 additions and 154 deletions
+22 -6
View File
@@ -1,10 +1,26 @@
import { Login } from './src/login.component';
import { Authentication } from './src/authentication.service';
export * from './src/login.component';
export * from './src/authentication.service';
/**
* @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 { AlfrescoLoginComponent } from './src/alfresco-login.component';
import { AlfrescoAuthenticationService } from './src/alfresco-authentication.service';
export * from './src/alfresco-login.component';
export * from './src/alfresco-authentication.service';
declare var _default: {
directives: typeof Login[];
providers: typeof Authentication[];
directives: typeof AlfrescoLoginComponent[];
providers: typeof AlfrescoAuthenticationService[];
};
export default _default;
export declare const ALFRESCO_LOGIN_DIRECTIVES: [any];
@@ -1,7 +1,7 @@
System.register(['./src/login.component', './src/authentication.service'], function(exports_1, context_1) {
System.register(['./src/alfresco-login.component', './src/alfresco-authentication.service'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var login_component_1, authentication_service_1;
var alfresco_login_component_1, alfresco_authentication_service_1;
var ALFRESCO_LOGIN_DIRECTIVES, ALFRESCO_AUTHENTICATION;
var exportedNames_1 = {
'ALFRESCO_LOGIN_DIRECTIVES': true,
@@ -16,21 +16,21 @@ System.register(['./src/login.component', './src/authentication.service'], funct
}
return {
setters:[
function (login_component_1_1) {
login_component_1 = login_component_1_1;
exportStar_1(login_component_1_1);
function (alfresco_login_component_1_1) {
alfresco_login_component_1 = alfresco_login_component_1_1;
exportStar_1(alfresco_login_component_1_1);
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
exportStar_1(authentication_service_1_1);
function (alfresco_authentication_service_1_1) {
alfresco_authentication_service_1 = alfresco_authentication_service_1_1;
exportStar_1(alfresco_authentication_service_1_1);
}],
execute: function() {
exports_1("default",{
directives: [login_component_1.Login],
providers: [authentication_service_1.Authentication]
directives: [alfresco_login_component_1.AlfrescoLoginComponent],
providers: [alfresco_authentication_service_1.AlfrescoAuthenticationService]
});
exports_1("ALFRESCO_LOGIN_DIRECTIVES", ALFRESCO_LOGIN_DIRECTIVES = [login_component_1.Login]);
exports_1("ALFRESCO_AUTHENTICATION", ALFRESCO_AUTHENTICATION = [authentication_service_1.Authentication]);
exports_1("ALFRESCO_LOGIN_DIRECTIVES", ALFRESCO_LOGIN_DIRECTIVES = [alfresco_login_component_1.AlfrescoLoginComponent]);
exports_1("ALFRESCO_AUTHENTICATION", ALFRESCO_AUTHENTICATION = [alfresco_authentication_service_1.AlfrescoAuthenticationService]);
}
}
});
@@ -1 +1 @@
{"version":3,"file":"ng2-alfresco-login.js","sourceRoot":"","sources":["ng2-alfresco-login.ts"],"names":[],"mappings":";;;;QA2Ba,yBAAyB,EACzB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;YANpC,oBAAe;gBACX,UAAU,EAAE,CAAC,uBAAK,CAAC;gBACnB,SAAS,EAAE,CAAC,uCAAc,CAAC;aAC9B,EAAA;YAEY,uCAAA,yBAAyB,GAAU,CAAC,uBAAK,CAAC,CAAA,CAAC;YAC3C,qCAAA,uBAAuB,GAAU,CAAC,uCAAc,CAAC,CAAA,CAAC"}
{"version":3,"file":"ng2-alfresco-login.js","sourceRoot":"","sources":["ng2-alfresco-login.ts"],"names":[],"mappings":";;;;QA2Ba,yBAAyB,EACzB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;YANpC,oBAAe;gBACX,UAAU,EAAE,CAAC,iDAAsB,CAAC;gBACpC,SAAS,EAAE,CAAC,+DAA6B,CAAC;aAC7C,EAAA;YAEY,uCAAA,yBAAyB,GAAU,CAAC,iDAAsB,CAAC,CAAA,CAAC;YAC5D,qCAAA,uBAAuB,GAAU,CAAC,+DAA6B,CAAC,CAAA,CAAC"}
@@ -14,16 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Login} from './src/login.component';
import {Authentication} from './src/authentication.service';
import {AlfrescoLoginComponent} from './src/alfresco-login.component';
import {AlfrescoAuthenticationService} from './src/alfresco-authentication.service';
export * from './src/login.component';
export * from './src/authentication.service';
export * from './src/alfresco-login.component';
export * from './src/alfresco-authentication.service';
export default {
directives: [Login],
providers: [Authentication]
directives: [AlfrescoLoginComponent],
providers: [AlfrescoAuthenticationService]
}
export const ALFRESCO_LOGIN_DIRECTIVES: [any] = [Login];
export const ALFRESCO_AUTHENTICATION: [any] = [Authentication];
export const ALFRESCO_LOGIN_DIRECTIVES: [any] = [AlfrescoLoginComponent];
export const ALFRESCO_AUTHENTICATION: [any] = [AlfrescoAuthenticationService];
@@ -8,6 +8,7 @@
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"format": "xo",
"test": "live-server --open=tests-runner.html"
},
"repository": {
@@ -53,5 +54,27 @@
"typescript": "^1.8.10",
"typings": "^0.7.12",
"xo": "^0.14.0"
},
"xo": {
"overrides": [
{
"files": "test/*.js",
"rules": {
"max-nested-callbacks": 0,
"handle-callback-err": 0
}
}
],
"rules": {
"no-lonely-if" : 0,
"one-var": 0,
"padded-blocks": 0,
"no-mixed-requires": 0,
"quotes": [
2,
"single",
"avoid-escape"
]
}
}
}
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs/Rx';
import { Http } from 'angular2/http';
export declare class Authentication {
export declare class AlfrescoAuthenticationService {
http: Http;
token: string;
private _host;
@@ -1,4 +1,4 @@
System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_1, context_1) {
System.register(['angular2/core', 'rxjs/Rx', 'angular2/http', '../../ng2-alfresco-core/services'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -10,8 +10,8 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1, Rx_1, http_1;
var Authentication;
var core_1, Rx_1, http_1, services_1;
var AlfrescoAuthenticationService;
return {
setters:[
function (core_1_1) {
@@ -22,24 +22,32 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
},
function (http_1_1) {
http_1 = http_1_1;
},
function (services_1_1) {
services_1 = services_1_1;
}],
execute: function() {
Authentication = (function () {
/**
* The AlfrescoAuthenticationService provide the login service and store the token in the localStorage
*/
AlfrescoAuthenticationService = (function () {
/**
* Constructor
* @param http
*/
function Authentication(http) {
function AlfrescoAuthenticationService(http, settings) {
this.http = http;
this.settings = settings;
this._host = 'http://192.168.99.100:8080';
this._baseUrl = this._host + '/alfresco/service/api/';
this.token = localStorage.getItem('token');
this._host = settings.host;
}
/**
* The method return tru if the user is logged in
* @returns {boolean}
*/
Authentication.prototype.isLoggedIn = function () {
AlfrescoAuthenticationService.prototype.isLoggedIn = function () {
return !!localStorage.getItem('token');
};
/**
@@ -49,7 +57,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* @param password
* @returns {Observable<R>|Observable<T>}
*/
Authentication.prototype.login = function (method, username, password) {
AlfrescoAuthenticationService.prototype.login = function (method, username, password) {
if (method === 'GET') {
return this.loginGet(username, password);
}
@@ -63,7 +71,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* @param password
* @returns {Observable<R>|Observable<T>}
*/
Authentication.prototype.loginGet = function (username, password) {
AlfrescoAuthenticationService.prototype.loginGet = function (username, password) {
var _this = this;
var searchParams = new http_1.URLSearchParams();
searchParams.set('u', username);
@@ -82,7 +90,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* @param password
* @returns {Observable<R>|Observable<T>}
*/
Authentication.prototype.loginPost = function (username, password) {
AlfrescoAuthenticationService.prototype.loginPost = function (username, password) {
var _this = this;
var credentials = '{ username: ' + username + ', password: ' + password + ' }';
var headers = new http_1.Headers();
@@ -101,7 +109,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* The method save the toke in the localStorage
* @param jwt
*/
Authentication.prototype.saveJwt = function (jwt) {
AlfrescoAuthenticationService.prototype.saveJwt = function (jwt) {
if (jwt) {
localStorage.setItem('token', jwt);
}
@@ -110,7 +118,7 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* The method remove the token from the local storage
* @returns {Observable<T>}
*/
Authentication.prototype.logout = function () {
AlfrescoAuthenticationService.prototype.logout = function () {
this.token = undefined;
localStorage.removeItem('token');
return Rx_1.Observable.of(true);
@@ -120,18 +128,18 @@ System.register(['angular2/core', 'rxjs/Rx', 'angular2/http'], function(exports_
* @param error
* @returns {ErrorObservable}
*/
Authentication.prototype.handleError = function (error) {
AlfrescoAuthenticationService.prototype.handleError = function (error) {
console.error(error);
return Rx_1.Observable.throw(error.json().error || 'Server error');
};
Authentication = __decorate([
AlfrescoAuthenticationService = __decorate([
core_1.Injectable(),
__metadata('design:paramtypes', [http_1.Http])
], Authentication);
return Authentication;
__metadata('design:paramtypes', [http_1.Http, services_1.AlfrescoSettingsService])
], AlfrescoAuthenticationService);
return AlfrescoAuthenticationService;
}());
exports_1("Authentication", Authentication);
exports_1("AlfrescoAuthenticationService", AlfrescoAuthenticationService);
}
}
});
//# sourceMappingURL=authentication.service.js.map
//# sourceMappingURL=alfresco-authentication.service.js.map
@@ -0,0 +1 @@
{"version":3,"file":"alfresco-authentication.service.js","sourceRoot":"","sources":["alfresco-authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAwBA;;eAEG;YAEH;gBAMI;;;mBAGG;gBACH,uCAAmB,IA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,GAAN;oBACI,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;oBACvB,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;oBAEjC,MAAM,CAAC,eAAU,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,CAAC;gBAED;;;;mBAIG;gBACK,mDAAW,GAAnB,UAAoB,KAAc;oBAC9B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBACrB,MAAM,CAAC,eAAU,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;gBAClE,CAAC;gBA/GL;oBAAC,iBAAU,EAAE;;iDAAA;gBAgHb,oCAAC;YAAD,CAAC,AA/GD,IA+GC;YA/GD,yEA+GC,CAAA"}
@@ -1,7 +1,7 @@
System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2/http/testing', './authentication.service'], function(exports_1, context_1) {
System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2/http/testing', './alfresco-authentication.service'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var testing_1, core_1, http_1, testing_2, authentication_service_1;
var testing_1, core_1, http_1, testing_2, alfresco_authentication_service_1;
return {
setters:[
function (testing_1_1) {
@@ -16,18 +16,18 @@ System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2
function (testing_2_1) {
testing_2 = testing_2_1;
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
function (alfresco_authentication_service_1_1) {
alfresco_authentication_service_1 = alfresco_authentication_service_1_1;
}],
execute: function() {
testing_1.describe('Authentication', function () {
testing_1.describe('AlfrescoAuthentication', function () {
var injector, backend, mockBackend, httpService, service;
beforeEach(function () {
injector = core_1.Injector.resolveAndCreate([
http_1.HTTP_PROVIDERS,
testing_2.MockBackend,
core_1.provide(http_1.XHRBackend, { useClass: testing_2.MockBackend }),
authentication_service_1.Authentication
alfresco_authentication_service_1.AlfrescoAuthenticationService
]);
var store = {};
spyOn(localStorage, 'getItem').and.callFake(function (key) {
@@ -49,7 +49,7 @@ System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2
mockBackend = injector.get(testing_2.MockBackend);
backend = injector.get(http_1.XHRBackend);
httpService = injector.get(http_1.Http);
service = injector.get(authentication_service_1.Authentication);
service = injector.get(alfresco_authentication_service_1.AlfrescoAuthenticationService);
});
testing_1.it('should return true and token if the user is logged in', function () {
service.saveJwt('fake-local-token');
@@ -88,4 +88,4 @@ System.register(['angular2/testing', 'angular2/core', 'angular2/http', 'angular2
}
}
});
//# sourceMappingURL=authentication.service.spec.js.map
//# sourceMappingURL=alfresco-authentication.service.spec.js.map
@@ -0,0 +1 @@
{"version":3,"file":"alfresco-authentication.service.spec.js","sourceRoot":"","sources":["alfresco-authentication.service.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;YAsBA,kBAAQ,CAAC,wBAAwB,EAAE;gBAC/B,IAAI,QAAQ,EACR,OAAO,EACP,WAAW,EACX,WAAW,EACX,OAAO,CAAC;gBAEZ,UAAU,CAAC;oBACP,QAAQ,GAAG,eAAQ,CAAC,gBAAgB,CAAC;wBACjC,qBAAc;wBACd,qBAAW;wBACX,cAAO,CAAC,iBAAU,EAAE,EAAC,QAAQ,EAAE,qBAAW,EAAC,CAAC;wBAC5C,+DAA6B;qBAChC,CAAC,CAAC;oBAEH,IAAI,KAAK,GAAG,EAAE,CAAC;oBAEf,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,GAAG;wBACrD,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACtB,CAAC,CAAC,CAAC;oBACH,KAAK,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,UAAU,GAAG,EAAE,KAAK;wBAC5D,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;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CAAC;wBACP,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACzC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;wBACxC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC5D,CAAC,CACJ,CAAC;gBACN,CAAC,CAAC,CAAC;YAEP,CAAC,CAAC,CAAC"}
@@ -18,9 +18,9 @@ import {it, describe} from 'angular2/testing';
import {provide, Injector} from 'angular2/core';
import {Http, HTTP_PROVIDERS, XHRBackend, Response, ResponseOptions} from 'angular2/http';
import {MockBackend} from 'angular2/http/testing';
import {Authentication} from './authentication.service';
import {AlfrescoAuthenticationService} from './alfresco-authentication.service';
describe('Authentication', () => {
describe('AlfrescoAuthentication', () => {
let injector,
backend,
mockBackend,
@@ -32,7 +32,7 @@ describe('Authentication', () => {
HTTP_PROVIDERS,
MockBackend,
provide(XHRBackend, {useClass: MockBackend}),
Authentication
AlfrescoAuthenticationService
]);
let store = {};
@@ -57,7 +57,7 @@ describe('Authentication', () => {
mockBackend = injector.get(MockBackend);
backend = injector.get(XHRBackend);
httpService = injector.get(Http);
service = injector.get(Authentication);
service = injector.get(AlfrescoAuthenticationService);
});
it('should return true and token if the user is logged in', () => {
@@ -17,11 +17,16 @@
import {Injectable} from 'angular2/core';
import {Observable} from 'rxjs/Rx';
import {Http, Headers, URLSearchParams, Response} from 'angular2/http';
import {AlfrescoSettingsService} from '../../ng2-alfresco-core/services';
declare let xml2json:any;
/**
* The AlfrescoAuthenticationService provide the login service and store the token in the localStorage
*/
@Injectable()
export class Authentication {
export class AlfrescoAuthenticationService {
token:string;
private _host:string = 'http://192.168.99.100:8080';
@@ -31,10 +36,11 @@ export class Authentication {
* Constructor
* @param http
*/
constructor(public http:Http) {
constructor(public http:Http,
private settings: AlfrescoSettingsService) {
this.token = localStorage.getItem('token');
this._host = settings.host;
}
/**
* The method return tru if the user is logged in
* @returns {boolean}
@@ -1,8 +1,8 @@
import { Router } from 'angular2/router';
import { ControlGroup, FormBuilder } from 'angular2/common';
import { Authentication } from './authentication.service';
export declare class Login {
auth: Authentication;
import { AlfrescoAuthenticationService } from './alfresco-authentication.service';
export declare class AlfrescoLoginComponent {
auth: AlfrescoAuthenticationService;
router: Router;
method: string;
form: ControlGroup;
@@ -13,7 +13,7 @@ export declare class Login {
* @param auth
* @param router
*/
constructor(fb: FormBuilder, auth: Authentication, router: Router);
constructor(fb: FormBuilder, auth: AlfrescoAuthenticationService, router: Router);
/**
* Method called on submit form
* @param value
@@ -1,4 +1,4 @@
System.register(['angular2/core', 'angular2/router', 'angular2/common', './authentication.service', 'ng2-translate/ng2-translate'], function(exports_1, context_1) {
System.register(['angular2/core', 'angular2/router', 'angular2/common', './alfresco-authentication.service', 'ng2-translate/ng2-translate'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
@@ -10,8 +10,8 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './authe
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1, router_1, common_1, authentication_service_1, ng2_translate_1;
var Login;
var core_1, router_1, common_1, alfresco_authentication_service_1, ng2_translate_1;
var AlfrescoLoginComponent;
return {
setters:[
function (core_1_1) {
@@ -23,21 +23,21 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './authe
function (common_1_1) {
common_1 = common_1_1;
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
function (alfresco_authentication_service_1_1) {
alfresco_authentication_service_1 = alfresco_authentication_service_1_1;
},
function (ng2_translate_1_1) {
ng2_translate_1 = ng2_translate_1_1;
}],
execute: function() {
Login = (function () {
AlfrescoLoginComponent = (function () {
/**
* Constructor
* @param fb
* @param auth
* @param router
*/
function Login(fb, auth, router) {
function AlfrescoLoginComponent(fb, auth, router) {
this.auth = auth;
this.router = router;
this.method = 'GET';
@@ -52,7 +52,7 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './authe
* @param value
* @param event
*/
Login.prototype.onSubmit = function (value, event) {
AlfrescoLoginComponent.prototype.onSubmit = function (value, event) {
var _this = this;
if (event) {
event.preventDefault();
@@ -67,7 +67,7 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './authe
* @param field
* @returns {boolean}
*/
Login.prototype.isErrorStyle = function (field) {
AlfrescoLoginComponent.prototype.isErrorStyle = function (field) {
if (componentHandler) {
componentHandler.upgradeAllRegistered();
}
@@ -81,22 +81,22 @@ System.register(['angular2/core', 'angular2/router', 'angular2/common', './authe
__decorate([
core_1.Input(),
__metadata('design:type', String)
], Login.prototype, "method", void 0);
Login = __decorate([
], AlfrescoLoginComponent.prototype, "method", void 0);
AlfrescoLoginComponent = __decorate([
core_1.Component({
selector: 'alfresco-login',
moduleId: __moduleName,
directives: [router_1.ROUTER_DIRECTIVES, common_1.FORM_DIRECTIVES],
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
templateUrl: './alfresco-login.component.html',
styleUrls: ['./alfresco-login.component.css'],
pipes: [ng2_translate_1.TranslatePipe]
}),
__metadata('design:paramtypes', [common_1.FormBuilder, authentication_service_1.Authentication, router_1.Router])
], Login);
return Login;
__metadata('design:paramtypes', [common_1.FormBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_1.Router])
], AlfrescoLoginComponent);
return AlfrescoLoginComponent;
}());
exports_1("Login", Login);
exports_1("AlfrescoLoginComponent", AlfrescoLoginComponent);
}
}
});
//# sourceMappingURL=login.component.js.map
//# sourceMappingURL=alfresco-login.component.js.map
@@ -0,0 +1 @@
{"version":3,"file":"alfresco-login.component.js","sourceRoot":"","sources":["alfresco-login.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,CAAC,KAAK,CAAC;oBACjB,CAAC;oBAAC,IAAI,CAAC,CAAC;wBACJ,MAAM,CAAC,IAAI,CAAC;oBAChB,CAAC;gBACL,CAAC;gBAlDD;oBAAC,YAAK,EAAE;;sEAAA;gBAVZ;oBAAC,gBAAS,CAAC;wBACP,QAAQ,EAAE,gBAAgB;wBAC1B,QAAQ,EAAE,YAAY;wBACtB,UAAU,EAAE,CAAC,0BAAiB,EAAE,wBAAe,CAAC;wBAChD,WAAW,EAAE,iCAAiC;wBAC9C,SAAS,EAAE,CAAC,gCAAgC,CAAC;wBAC7C,KAAK,EAAE,CAAC,6BAAa,CAAC;qBAEzB,CAAC;;0CAAA;gBAqDF,6BAAC;YAAD,CAAC,AApDD,IAoDC;YApDD,2DAoDC,CAAA"}
@@ -1,7 +1,7 @@
System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angular2/core', './login.component', 'rxjs/Rx', './authentication.service', 'angular2/src/router/router', 'angular2/router', 'angular2/src/mock/location_mock'], function(exports_1, context_1) {
System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angular2/core', './alfresco-login.component', 'rxjs/Rx', './alfresco-authentication.service', 'angular2/src/router/router', 'angular2/router', 'angular2/src/mock/location_mock'], function(exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
var browser_1, testing_1, core_1, login_component_1, Rx_1, authentication_service_1, router_1, router_2, location_mock_1;
var browser_1, testing_1, core_1, alfresco_login_component_1, Rx_1, alfresco_authentication_service_1, router_1, router_2, location_mock_1;
var AuthenticationMock;
return {
setters:[
@@ -14,14 +14,14 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
function (core_1_1) {
core_1 = core_1_1;
},
function (login_component_1_1) {
login_component_1 = login_component_1_1;
function (alfresco_login_component_1_1) {
alfresco_login_component_1 = alfresco_login_component_1_1;
},
function (Rx_1_1) {
Rx_1 = Rx_1_1;
},
function (authentication_service_1_1) {
authentication_service_1 = authentication_service_1_1;
function (alfresco_authentication_service_1_1) {
alfresco_authentication_service_1 = alfresco_authentication_service_1_1;
},
function (router_1_1) {
router_1 = router_1_1;
@@ -46,11 +46,11 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
}
};
AuthenticationMock.prototype.getProviders = function () {
return [core_1.provide(authentication_service_1.Authentication, { useValue: this })];
return [core_1.provide(alfresco_authentication_service_1.AlfrescoAuthenticationService, { useValue: this })];
};
return AuthenticationMock;
}());
testing_1.describe('Login', function () {
testing_1.describe('AlfrescoLogin', function () {
var authService, location, router;
testing_1.setBaseTestProviders(browser_1.TEST_BROWSER_PLATFORM_PROVIDERS, browser_1.TEST_BROWSER_APPLICATION_PROVIDERS);
testing_1.beforeEachProviders(function () {
@@ -59,7 +59,7 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
authService.getProviders(),
router_2.RouteRegistry,
core_1.provide(router_2.Location, { useClass: location_mock_1.SpyLocation }),
core_1.provide(router_2.ROUTER_PRIMARY_COMPONENT, { useValue: login_component_1.Login }),
core_1.provide(router_2.ROUTER_PRIMARY_COMPONENT, { useValue: alfresco_login_component_1.AlfrescoLoginComponent }),
core_1.provide(router_2.Router, { useClass: router_1.RootRouter })
];
});
@@ -67,18 +67,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
router = r;
location = l;
}));
testing_1.it('should render `Login` header', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should render `Login` form with input fields user and password with default value', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.then(function (fixture) {
var element = fixture.nativeElement;
testing_1.expect(element.querySelector('h2').innerText).toBe('Login');
testing_1.expect(element.querySelector('form')).toBeDefined();
});
}));
testing_1.it('should render `Login` form with input fields user and password with default value', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
var element = fixture.nativeElement;
testing_1.expect(element.querySelector('form')).toBeDefined();
@@ -88,9 +79,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(element.querySelector('input[type="text"]').value).toEqual('');
});
}));
testing_1.it('should render the new values after change the user and password values', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should render the new values after change the user and password values', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
var compiled = fixture.debugElement.nativeElement;
var password = compiled.querySelector('input[type="password"]');
@@ -101,11 +92,11 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(compiled.querySelector('input[type="text"]').value).toEqual('my username');
});
}));
testing_1.it('should navigate to Home route after the login OK ', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should navigate to Home route after the login OK ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
router.config([new router_2.Route({ path: '/home', name: 'Home', component: login_component_1.Login })]);
router.config([new router_2.Route({ path: '/home', name: 'Home', component: alfresco_login_component_1.AlfrescoLoginComponent })]);
spyOn(router, 'navigate').and.callThrough();
var compiled = fixture.debugElement.nativeElement;
var password = compiled.querySelector('input[type="password"]');
@@ -117,9 +108,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(router.navigate).toHaveBeenCalledWith(['Home']);
});
}));
testing_1.it('should return error with a wrong username ', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should return error with a wrong username ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var compiled = fixture.debugElement.nativeElement;
@@ -131,9 +122,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(fixture.componentInstance.error).toBe(true);
});
}));
testing_1.it('should return error with a wrong password ', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should return error with a wrong password ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var compiled = fixture.debugElement.nativeElement;
@@ -145,9 +136,9 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
testing_1.expect(fixture.componentInstance.error).toBe(true);
});
}));
testing_1.it('should return error with a wrong username and password ', testing_1.injectAsync([testing_1.TestComponentBuilder, authentication_service_1.Authentication, router_2.Router], function (tcb, authService, router) {
testing_1.it('should return error with a wrong username and password ', testing_1.injectAsync([testing_1.TestComponentBuilder, alfresco_authentication_service_1.AlfrescoAuthenticationService, router_2.Router], function (tcb, authService, router) {
return tcb
.createAsync(login_component_1.Login)
.createAsync(alfresco_login_component_1.AlfrescoLoginComponent)
.then(function (fixture) {
spyOn(router, 'navigate').and.callThrough();
var compiled = fixture.debugElement.nativeElement;
@@ -163,4 +154,4 @@ System.register(['angular2/platform/testing/browser', 'angular2/testing', 'angul
}
}
});
//# sourceMappingURL=login.component.spec.js.map
//# sourceMappingURL=alfresco-login.component.spec.js.map
File diff suppressed because one or more lines are too long
@@ -17,9 +17,9 @@
import {TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS} from 'angular2/platform/testing/browser';
import {it, describe, expect, inject, injectAsync, beforeEach, beforeEachProviders, TestComponentBuilder, setBaseTestProviders} from 'angular2/testing';
import {Component, provide, Injector} from 'angular2/core';
import {Login} from './login.component';
import {AlfrescoLoginComponent} from './alfresco-login.component';
import {Observable} from 'rxjs/Rx';
import {Authentication} from './authentication.service';
import {AlfrescoAuthenticationService} from './alfresco-authentication.service';
import { RootRouter } from 'angular2/src/router/router';
import { Location, Router, RouteRegistry, ROUTER_PRIMARY_COMPONENT, Route } from 'angular2/router';
import { SpyLocation } from 'angular2/src/mock/location_mock';
@@ -37,11 +37,11 @@ class AuthenticationMock {
}
getProviders():Array<any> {
return [provide(Authentication, {useValue: this})];
return [provide(AlfrescoAuthenticationService, {useValue: this})];
}
}
describe('Login', () => {
describe('AlfrescoLogin', () => {
let authService, location, router;
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
@@ -53,7 +53,7 @@ describe('Login', () => {
authService.getProviders(),
RouteRegistry,
provide(Location, {useClass: SpyLocation}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: Login}),
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AlfrescoLoginComponent}),
provide(Router, {useClass: RootRouter})
];
});
@@ -63,19 +63,9 @@ describe('Login', () => {
location = l;
}));
it('should render `Login` header', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should render `Login` form with input fields user and password with default value', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.then((fixture) => {
let element = fixture.nativeElement;
expect(element.querySelector('h2').innerText).toBe('Login');
expect(element.querySelector('form')).toBeDefined();
});
}));
it('should render `Login` form with input fields user and password with default value', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
let element = fixture.nativeElement;
expect(element.querySelector('form')).toBeDefined();
@@ -87,9 +77,9 @@ describe('Login', () => {
}));
it('should render the new values after change the user and password values', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should render the new values after change the user and password values', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
let compiled = fixture.debugElement.nativeElement;
@@ -104,11 +94,11 @@ describe('Login', () => {
});
}));
it('should navigate to Home route after the login OK ', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should navigate to Home route after the login OK ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
router.config([new Route({path: '/home', name: 'Home', component: Login})]);
router.config([new Route({path: '/home', name: 'Home', component: AlfrescoLoginComponent})]);
spyOn(router, 'navigate').and.callThrough();
let compiled = fixture.debugElement.nativeElement;
@@ -125,9 +115,9 @@ describe('Login', () => {
});
}));
it('should return error with a wrong username ', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should return error with a wrong username ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let compiled = fixture.debugElement.nativeElement;
@@ -144,9 +134,9 @@ describe('Login', () => {
});
}));
it('should return error with a wrong password ', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should return error with a wrong password ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let compiled = fixture.debugElement.nativeElement;
@@ -163,9 +153,9 @@ describe('Login', () => {
});
}));
it('should return error with a wrong username and password ', injectAsync([TestComponentBuilder, Authentication, Router], (tcb:TestComponentBuilder, authService:Authentication, router:Router) => {
it('should return error with a wrong username and password ', injectAsync([TestComponentBuilder, AlfrescoAuthenticationService, Router], (tcb:TestComponentBuilder, authService:AlfrescoAuthenticationService, router:Router) => {
return tcb
.createAsync(Login)
.createAsync(AlfrescoLoginComponent)
.then((fixture) => {
spyOn(router, 'navigate').and.callThrough();
let compiled = fixture.debugElement.nativeElement;
@@ -17,8 +17,8 @@
import {Component, Input} from 'angular2/core';
import {Router, ROUTER_DIRECTIVES} from 'angular2/router';
import {FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators} from 'angular2/common';
import {Authentication} from './authentication.service';
import {TRANSLATE_PROVIDERS, TranslateService, TranslatePipe, TranslateLoader, TranslateStaticLoader} from 'ng2-translate/ng2-translate';
import {AlfrescoAuthenticationService} from './alfresco-authentication.service';
import {TranslatePipe} from 'ng2-translate/ng2-translate';
declare let componentHandler;
declare let __moduleName:string;
@@ -26,12 +26,12 @@ declare let __moduleName:string;
selector: 'alfresco-login',
moduleId: __moduleName,
directives: [ROUTER_DIRECTIVES, FORM_DIRECTIVES],
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
templateUrl: './alfresco-login.component.html',
styleUrls: ['./alfresco-login.component.css'],
pipes: [TranslatePipe]
})
export class Login {
export class AlfrescoLoginComponent {
@Input() method:string = 'GET';
form:ControlGroup;
@@ -43,7 +43,7 @@ export class Login {
* @param auth
* @param router
*/
constructor(fb:FormBuilder, public auth:Authentication, public router:Router) {
constructor(fb:FormBuilder, public auth:AlfrescoAuthenticationService, public router:Router) {
this.form = fb.group({
username: ['', Validators.compose([Validators.required, Validators.minLength(4)])],
password: ['', Validators.required]
@@ -1 +0,0 @@
{"version":3,"file":"authentication.service.js","sourceRoot":"","sources":["authentication.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;YAuBA;gBAMI;;;mBAGG;gBACH,wBAAmB,IAAS;oBAAT,SAAI,GAAJ,IAAI,CAAK;oBAPpB,UAAK,GAAU,4BAA4B,CAAC;oBAC5C,aAAQ,GAAU,IAAI,CAAC,KAAK,GAAG,wBAAwB,CAAC;oBAO5D,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC/C,CAAC;gBAED;;;mBAGG;gBACH,mCAAU,GAAV;oBACI,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC3C,CAAC;gBAED;;;;;;mBAMG;gBACH,8BAAK,GAAL,UAAM,MAAa,EAAE,QAAe,EAAE,QAAe;oBACjD,EAAE,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC;wBACnB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC7C,CAAC;oBAAC,IAAI,CAAC,CAAC;wBACJ,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;oBAC9C,CAAC;gBACL,CAAC;gBAED;;;;;mBAKG;gBACH,iCAAQ,GAAR,UAAS,QAAe,EAAE,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EAAE,CAAC,0BAAiB,EAAE,wBAAe,CAAC;wBAChD,WAAW,EAAE,wBAAwB;wBACrC,SAAS,EAAE,CAAC,uBAAuB,CAAC;wBACpC,KAAK,EAAE,CAAC,6BAAa,CAAC;qBAEzB,CAAC;;yBAAA;gBAqDF,YAAC;YAAD,CAAC,AApDD,IAoDC;YApDD,yBAoDC,CAAA"}
@@ -26,14 +26,24 @@
// for imports from the app folder
System.config({
packages: {
'src': {defaultExtension: 'js'}
'src': {defaultExtension: 'js'},
'ng2-translate': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
},
map: {
'ng2-translate': 'node_modules/ng2-translate',
'rxjs': 'node_modules/rxjs'
}
});
// #3. Import the spec file explicitly
Promise.all([
System.import('src/authentication.service.spec'),
System.import('src/login.component.spec')
System.import('src/alfresco-authentication.service.spec'),
System.import('src/alfresco-login.component.spec')
])
// #4. wait for all imports to load ...
// then re-execute `window.onload` which