mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
page title service (#2403)
This commit is contained in:
committed by
Maurizio Vitale
parent
e756db03cd
commit
7c1bd46642
@@ -2,7 +2,7 @@
|
||||
"ecmHost": "http://{hostname}:{port}/ecm",
|
||||
"bpmHost": "http://{hostname}:{port}/bpm",
|
||||
"application": {
|
||||
"name": "Alfresco"
|
||||
"name": "Alfresco ADF Appplication"
|
||||
},
|
||||
"pagination": {
|
||||
"size": 25
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"ecmHost": "http://{hostname}",
|
||||
"bpmHost": "http://{hostname}",
|
||||
"application": {
|
||||
"name": "Alfresco"
|
||||
"name": "Alfresco ADF Appplication"
|
||||
},
|
||||
"pagination": {
|
||||
"size": 25
|
||||
|
@@ -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 {
|
||||
|
@@ -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,
|
||||
|
@@ -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'
|
||||
};
|
||||
|
@@ -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');
|
||||
});
|
||||
});
|
@@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user