Start adding ecmUser component

This commit is contained in:
Vito Albano
2016-09-16 11:46:16 +01:00
parent 79fc3085c0
commit 18fbdb75d0
29 changed files with 1138 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/*!
* @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 EcmCompanyModel {
organization: string;
address1: string;
address2: string;
address3: string;
postcode: string;
telephone: string;
fax: string;
email: string;
}

View File

@@ -0,0 +1,39 @@
/*!
* @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 { EcmCompanyModel } from './ecmCompany.model';
export class EcmUserModel {
id: string;
firstName: string;
lastName: string;
description: string;
avatarId: string;
email: string;
skypeId: string;
googleId: string;
instantMessageId: string;
jobTitle: string;
location: string;
company: EcmCompanyModel;
mobile: string;
telephone: string;
statusUpdatedAt: string;
userStatus: string;
enabled: boolean;
emailNotificationsEnabled: boolean;
}

View File

@@ -0,0 +1,63 @@
/*!
* @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 { AlfrescoApiService } from 'ng2-alfresco-core';
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { EcmUserModel } from '../models/ecmUser.model';
/**
*
* ECMUserService retrieve all the information of an Ecm user.
*
* @returns {ECMUserService} .
*/
@Injectable()
export class ECMUserService {
constructor(private apiService: AlfrescoApiService) {}
/**
* get User Information via ECM
* @param userName - the user name
*/
getUserInfo(userName: string): Observable<EcmUserModel> {
return Observable.fromPromise(this.callApiGetPersonInfo(userName))
.map( data => <EcmUserModel> data )
.do(
data => console.log('Node data', data)
) // eyeball results in the console
.catch(this.handleError);
}
private callApiGetPersonInfo(userName: string, opts?: any) {
return this.apiService.getInstance().core.peopleApi.getPerson(userName, opts);
}
/**
* Throw the error
* @param error
* @returns {ErrorObservable}
*/
private handleError(error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
console.error(error);
return Observable.throw(error || 'Server error');
}
}

View File

@@ -0,0 +1 @@
<div [innerHtml]="ecmUser">TEST</div>

View File

@@ -0,0 +1,16 @@
import {describe, expect, it, inject} from '@angular/core/testing';
import { TestComponentBuilder } from '@angular/compiler/testing';
import { UserInfoComponent } from '../src/userinfo.component';
describe('Basic Example test ng2-alfresco-userinfo', () => {
it('Test hello world', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(UserInfoComponent)
.then((fixture) => {
let element = fixture.nativeElement;
expect(element.querySelector('h1')).toBeDefined();
expect(element.getElementsByTagName('h1')[0].innerHTML).toEqual('Hello World Angular 2 ng2-alfresco-userinfo');
});
}));
});

View File

@@ -0,0 +1,31 @@
import { Component } from '@angular/core';
import { ECMUserService } from './services/ecmUser.service';
import { EcmUserModel } from './models/ecmUser.model';
@Component({
selector: 'ng2-alfresco-userinfo',
styles: [`:host h1 { font-size:22px }`],
template: `<h1>Hello World Angular 2 ng2-alfresco-userinfo</h1> <button (click)='doQueryUser()'>Do Query</button>`,
providers: [ ECMUserService ]
})
export class UserInfoComponent {
private ecmUser: EcmUserModel;
constructor(private ecmUserService: ECMUserService) {
console.log('User info component constr');
}
doQueryUser() {
this.ecmUserService.getUserInfo('admin')
.subscribe(
res => this.ecmUser = <EcmUserModel> res.entry
);
}
}