page title service (#2403)

This commit is contained in:
Denys Vuika
2017-10-02 12:17:28 +01:00
committed by Maurizio Vitale
parent e756db03cd
commit 7c1bd46642
7 changed files with 146 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
"ecmHost": "http://{hostname}:{port}/ecm",
"bpmHost": "http://{hostname}:{port}/bpm",
"application": {
"name": "Alfresco"
"name": "Alfresco ADF Appplication"
},
"pagination": {
"size": 25

View File

@@ -2,7 +2,7 @@
"ecmHost": "http://{hostname}",
"bpmHost": "http://{hostname}",
"application": {
"name": "Alfresco"
"name": "Alfresco ADF Appplication"
},
"pagination": {
"size": 25

View File

@@ -16,7 +16,7 @@
*/
import { Component, ViewEncapsulation } from '@angular/core';
import { AlfrescoSettingsService, AlfrescoTranslationService, StorageService } from 'ng2-alfresco-core';
import { AlfrescoSettingsService, AlfrescoTranslationService, PageTitle, StorageService } from 'ng2-alfresco-core';
@Component({
selector: 'adf-app',
@@ -29,8 +29,10 @@ export class AppComponent {
constructor(private settingsService: AlfrescoSettingsService,
private translateService: AlfrescoTranslationService,
private storage: StorageService) {
private storage: StorageService,
pageTitle: PageTitle) {
this.setProvider();
pageTitle.setTitle();
}
isAPageWithHeaderBar(): boolean {

View File

@@ -45,6 +45,7 @@ import { CookieService } from './src/services/cookie.service';
import { LogService } from './src/services/log.service';
import { LogServiceMock } from './src/services/log.service';
import { NotificationService } from './src/services/notification.service';
import { PageTitle } from './src/services/page-title.service';
import { RenditionsService } from './src/services/renditions.service';
import { StorageService } from './src/services/storage.service';
import { ThumbnailService } from './src/services/thumbnail.service';
@@ -72,6 +73,7 @@ import { MomentDateAdapter } from './src/utils/momentDateAdapter';
export { CreateFolderDialogComponent } from './src/dialogs/create-folder.dialog';
export { DownloadZipDialogComponent } from './src/dialogs/download-zip.dialog';
export { PageTitle } from './src/services/page-title.service';
export { ContentService } from './src/services/content.service';
export { StorageService } from './src/services/storage.service';
export { CookieService } from './src/services/cookie.service';
@@ -164,6 +166,7 @@ export * from './src/services/search.service';
export function providers() {
return [
PageTitle,
UserPreferencesService,
NotificationService,
LogService,

View File

@@ -23,6 +23,9 @@ import { ObjectUtils } from '../utils/object-utils';
export class AppConfigService {
config: any = {
application: {
name: 'Alfresco ADF Application'
},
ecmHost: 'http://{hostname}:{port}/ecm',
bpmHost: 'http://{hostname}:{port}/bpm'
};

View File

@@ -0,0 +1,99 @@
/*!
* @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 { inject, TestBed } from '@angular/core/testing';
import { Title } from '@angular/platform-browser';
import { AppConfigService } from './app-config.service';
import { PageTitle } from './page-title.service';
class TestConfig {
private setup: any = {
applicationName: undefined
};
titleService: Title = null;
appTitleService: PageTitle = null;
constructor(setup: any = {}) {
Object.assign(this.setup, setup);
const titleServiceProvider = {
provide: Title,
useValue: {
setTitle: jasmine.createSpy('setTitleSpy')
}
};
const appConfigProvider = {
provide: AppConfigService,
useValue: {
config: {
application: {
name: this.setup.applicationName
}
},
get: () => this.setup.applicationName
}
};
TestBed.configureTestingModule({
providers: [
titleServiceProvider,
appConfigProvider,
PageTitle
]
});
inject([ Title, PageTitle ], (titleService, appTitleService) => {
this.titleService = titleService;
this.appTitleService = appTitleService;
})();
}
}
describe('AppTitle service', () => {
it('sets default application name', () => {
const { appTitleService, titleService } = new TestConfig({
applicationName: undefined
});
appTitleService.setTitle();
expect(titleService.setTitle)
.toHaveBeenCalledWith('Alfresco ADF Application');
});
it('sets only the application name', () => {
const { appTitleService, titleService } = new TestConfig({
applicationName: 'My application'
});
appTitleService.setTitle();
expect(titleService.setTitle)
.toHaveBeenCalledWith('My application');
});
it('appends application name to the title', () => {
const { appTitleService, titleService } = new TestConfig({
applicationName: 'My application'
});
appTitleService.setTitle('My page');
expect(titleService.setTitle)
.toHaveBeenCalledWith('My page - My application');
});
});

View File

@@ -0,0 +1,35 @@
/*!
* @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 } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { AppConfigService } from './app-config.service';
@Injectable()
export class PageTitle {
constructor(
private titleService: Title,
private appConfig: AppConfigService) {}
setTitle(value: string = '') {
const name = this.appConfig.get('application.name') || 'Alfresco ADF Application';
const title = value ? `${value} - ${name}` : `${name}`;
this.titleService.setTitle(title);
}
}