New packages org (#2639)

New packages org
This commit is contained in:
Eugenio Romano
2017-11-16 14:12:52 +00:00
committed by GitHub
parent 6a24c6ef75
commit a52bb5600a
1984 changed files with 17179 additions and 40423 deletions

View File

@@ -0,0 +1,18 @@
/*!
* @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 './public-api';

View File

@@ -0,0 +1,20 @@
/*!
* @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 './webscript.component';
export * from './webscript.module';

View File

@@ -0,0 +1,16 @@
<div *ngIf="showData">
<div *ngIf="contentType === 'JSON'" id="webscript-data-JSON">{{data | json}}</div>
<div *ngIf="contentType === 'HTML'" id="webscript-data-HTML" [innerHTML]="data"></div>
<div *ngIf="contentType === 'TEXT'" id="webscript-data-TEXT">{{data}}</div>
<div *ngIf="isDataTableContent()">
<adf-datatable id="webscript-datatable-wrapper" [data]="data"></adf-datatable>
<div>
<div *ngIf="showError" id="error">{{'WEBSCRIPT.ERROR' | translate: {
data: data,
contentType: contentType
}
}}
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,224 @@
/*!
* @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 { DebugElement } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, CoreModule } from '@alfresco/core';
import { DataTableModule } from '@alfresco/core';
import { WebscriptComponent } from './webscript.component';
declare let jasmine: any;
describe('WebscriptComponent', () => {
let component: WebscriptComponent;
let fixture: ComponentFixture<WebscriptComponent>;
let debug: DebugElement;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule,
DataTableModule
],
declarations: [
WebscriptComponent
]
}).compileComponents();
}));
beforeEach(() => {
let appConfig: AppConfigService = TestBed.get(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
fixture = TestBed.createComponent(WebscriptComponent);
component = fixture.componentInstance;
debug = fixture.debugElement;
element = fixture.nativeElement;
component = fixture.componentInstance;
component.scriptPath = 'fakePath';
component.showData = true;
fixture.detectChanges();
});
describe('View', () => {
it('html wrapper should be present', () => {
expect(element.querySelector('#webscript-html-wrapper')).toBeDefined();
});
it('wrapper should be hide if showData is false', () => {
expect(element.querySelector('#webscript-html-wrapper')).toBeDefined();
});
it('JSON datatable wrapper should be present', () => {
expect(element.querySelector('#webscript-json-wrapper')).toBeDefined();
});
it('plain text datatable wrapper should be present', () => {
expect(element.querySelector('#webscript-plaintext-wrapper')).toBeDefined();
});
});
describe('Content tests', () => {
beforeEach(() => {
jasmine.Ajax.install();
});
afterEach(() => {
jasmine.Ajax.uninstall();
});
it('url should be the one configured by the input param', (done) => {
component.scriptPath = 'sample/folder/Company%20Home';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://localhost:9876/ecm/alfresco/service/sample/folder/Company%20Home');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'text/plain',
responseText: '<div></div>'
});
});
it('TEXT response should be displayed', (done) => {
component.scriptPath = 'sample/folder/Company%20Home';
component.contentType = 'TEXT';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(element.querySelector('#webscript-data-TEXT').innerHTML)
.toBe('text test');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'text/html',
responseText: 'text test'
});
});
it('JSON response should be displayed', (done) => {
component.scriptPath = 'sample/folder/Company%20Home';
component.contentType = 'JSON';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(JSON.parse(element.querySelector('#webscript-data-JSON').innerHTML)[0].name).toBe('Name 1');
expect(JSON.parse(element.querySelector('#webscript-data-JSON').innerHTML)[1].name).toBe('Name 2');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: [{id: 1, name: 'Name 1'},
{id: 2, name: 'Name 2'}]
});
});
xit('HTML response should be displayed', (done) => {
component.scriptPath = 'sample/folder/Company%20Home';
component.contentType = 'HTML';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(element.querySelector('#webscript-data-HTML').innerHTML)
.toBe('&lt;test-element-id&gt;&lt;test-elemt-id&gt;');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'text/html',
responseText: '<test-element-id><test-elemt-id>'
});
});
it('datatable response should be displayed', (done) => {
// reset MDL handler
window['componentHandler'] = null;
component.scriptPath = 'sample/folder/Company%20Home';
component.contentType = 'DATATABLE';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(element.querySelector('#webscript-datatable-wrapper').innerHTML).toBeDefined();
done();
});
let dataTable = {
data: [
{id: 1, name: 'Name 1'},
{id: 2, name: 'Name 2'}
],
schema: [{
type: 'text',
key: 'id',
title: 'Id',
sortable: true
}, {
type: 'text',
key: 'name',
title: 'Name',
sortable: true
}]
};
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: dataTable
});
});
it('datatable response should be displayed also if no schema is provided', (done) => {
// reset MDL handler
window['componentHandler'] = null;
component.scriptPath = 'sample/folder/Company%20Home';
component.contentType = 'DATATABLE';
component.ngOnChanges(null).then(() => {
fixture.detectChanges();
expect(element.querySelector('#webscript-datatable-wrapper').innerHTML).toBeDefined();
done();
});
let dataTable = {
data: [
{id: 1, name: 'Name 1'},
{id: 2, name: 'Name 2'}
]
};
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: dataTable
});
});
});
});

View File

@@ -0,0 +1,136 @@
/*!
* @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 { ObjectDataTableAdapter } from '@alfresco/core';
import { AlfrescoApiService, LogService } from '@alfresco/core';
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
/**
* <adf-webscript-get [scriptPath]="string"
* [scriptArgs]="Object"
* [contextRoot]="string"
* [servicePath]="string"
* [contentType]="JSON|HTML|DATATABLE"
* (success)="customMethod($event)>
* </adf-webscript-get>
*
* This component, provide a get webscript viewer
*
* @InputParam {string} scriptPath path to Web Script (as defined by Web Script)
* @InputParam {Object} scriptArgs arguments to pass to Web Script
* @InputParam {string} contextRoot path where application is deployed default value 'alfresco'
* @InputParam {string} servicePath path where Web Script service is mapped default value 'service'
* @InputParam {string} contentType JSON | HTML | DATATABLE | TEXT
*
* @Output - success - The event is emitted when the data are recived
*
* @returns {WebscriptComponent} .
*/
@Component({
selector: 'adf-webscript-get',
templateUrl: 'webscript.component.html'
})
export class WebscriptComponent implements OnChanges {
@Input()
scriptPath: string;
@Input()
scriptArgs: any;
@Input()
showData: boolean = true;
@Input()
contextRoot: string = 'alfresco';
@Input()
servicePath: string = 'service';
@Input()
contentType: string = 'TEXT';
@Output()
success = new EventEmitter();
data: any = undefined;
showError: boolean = false;
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}
ngOnChanges(changes) {
if (this.showData) {
this.clean();
}
return new Promise((resolve, reject) => {
this.apiService.getInstance().webScript.executeWebScript('GET', this.scriptPath, this.scriptArgs, this.contextRoot, this.servicePath).then((webScriptdata) => {
this.data = webScriptdata;
if (this.showData) {
if (this.contentType === 'DATATABLE') {
this.data = this.showDataAsDataTable(webScriptdata);
}
}
this.success.emit(this.data);
resolve();
}, (error) => {
this.logService.log('Error' + error);
reject();
});
});
}
/**
* show the data in a ng2-alfresco-datatable
*
* @param data
*
* @retutns the data as datatable
*/
showDataAsDataTable(data: any) {
let datatableData: any = null;
try {
if (!data.schema) {
data.schema = ObjectDataTableAdapter.generateSchema(data.data);
}
if (data.schema && data.schema.length > 0) {
this.data = new ObjectDataTableAdapter(data.data, data.schema);
}
} catch (e) {
this.logService.error('error during the cast as datatable');
}
return datatableData;
}
clean() {
this.data = undefined;
}
isDataTableContent() {
return this.contentType === 'DATATABLE';
}
}

View File

@@ -0,0 +1,41 @@
/*!
* @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 { DataTableModule, PipeModule } from '@alfresco/core';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { MaterialModule } from '../material.module';
import { WebscriptComponent } from './webscript.component';
@NgModule({
imports: [
CommonModule,
PipeModule,
MaterialModule,
DataTableModule,
TranslateModule
],
exports: [
WebscriptComponent
],
declarations: [
WebscriptComponent
]
})
export class WebScriptModule {}