Merge pull request #2000 from steven-zou/master

Override page title and search placeholder when in VIC mode
This commit is contained in:
Steven Zou 2017-04-12 19:22:21 +08:00 committed by GitHub
commit 4b99f3db3a
8 changed files with 41 additions and 16 deletions

View File

@ -131,6 +131,7 @@ export class SignInComponent implements AfterViewChecked, OnInit {
let expires: number = expireDays * 3600 * 24 * 1000; let expires: number = expireDays * 3600 * 24 * 1000;
let date = new Date(Date.now() + expires); let date = new Date(Date.now() + expires);
let cookieptions = new CookieOptions({ let cookieptions = new CookieOptions({
path: "/",
expires: date expires: date
}); });
this.cookie.put(remCookieKey, this.signInCredential.principal, cookieptions); this.cookie.put(remCookieKey, this.signInCredential.principal, cookieptions);

View File

@ -4,7 +4,8 @@ import { CookieService } from 'angular2-cookie/core';
import { supportedLangs, enLang } from './shared/shared.const'; import { supportedLangs, enLang } from './shared/shared.const';
import { SessionService } from './shared/session.service'; import { SessionService } from './shared/session.service';
import { AppConfigService } from './app-config.service';
import { Title } from '@angular/platform-browser';
@Component({ @Component({
selector: 'harbor-app', selector: 'harbor-app',
@ -14,7 +15,9 @@ export class AppComponent {
constructor( constructor(
private translate: TranslateService, private translate: TranslateService,
private cookie: CookieService, private cookie: CookieService,
private session: SessionService) { private session: SessionService,
private appConfigService: AppConfigService,
private titleService: Title) {
translate.addLangs(supportedLangs); translate.addLangs(supportedLangs);
translate.setDefaultLang(enLang); translate.setDefaultLang(enLang);
@ -29,6 +32,16 @@ export class AppComponent {
let selectedLang = this.isLangMatch(langSetting, supportedLangs) ? langSetting : enLang; let selectedLang = this.isLangMatch(langSetting, supportedLangs) ? langSetting : enLang;
translate.use(selectedLang); translate.use(selectedLang);
//this.session.switchLanguage(selectedLang).catch(error => console.error(error)); //this.session.switchLanguage(selectedLang).catch(error => console.error(error));
//Override page title
let key: string = "APP_TITLE.HARBOR";
if (this.appConfigService.isIntegrationMode()) {
key = "APP_TITLE.REG";
}
translate.get(key).subscribe((res: string) => {
this.titleService.setTitle(res);
});
} }
private isLangMatch(browserLang: string, supportedLangs: string[]) { private isLangMatch(browserLang: string, supportedLangs: string[]) {

View File

@ -1,5 +1,5 @@
<form class="search"> <form class="search">
<label for="search_input"> <label for="search_input">
<input #globalSearchBox name="globalSearchBox" [(ngModel)]="searchTerm" id="search_input" type="text" (keyup)="search(globalSearchBox.value)" placeholder='{{"GLOBAL_SEARCH.PLACEHOLDER" | translate}}'> <input #globalSearchBox name="globalSearchBox" [(ngModel)]="searchTerm" id="search_input" type="text" (keyup)="search(globalSearchBox.value)" placeholder='{{placeholderText | translate}}'>
</label> </label>
</form> </form>

View File

@ -6,6 +6,8 @@ import { Subscription } from 'rxjs/Subscription';
import { SearchTriggerService } from './search-trigger.service'; import { SearchTriggerService } from './search-trigger.service';
import { AppConfigService } from '../../app-config.service';
import 'rxjs/add/operator/debounceTime'; import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged'; import 'rxjs/add/operator/distinctUntilChanged';
@ -27,9 +29,13 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
private isResPanelOpened: boolean = false; private isResPanelOpened: boolean = false;
private searchTerm: string = ""; private searchTerm: string = "";
//Placeholder text
placeholderText: string = "GLOBAL_SEARCH.PLACEHOLDER";
constructor( constructor(
private searchTrigger: SearchTriggerService, private searchTrigger: SearchTriggerService,
private router: Router) { } private router: Router,
private appConfigService: AppConfigService) { }
//Implement ngOnIni //Implement ngOnIni
ngOnInit(): void { ngOnInit(): void {
@ -42,6 +48,10 @@ export class GlobalSearchComponent implements OnInit, OnDestroy {
this.closeSub = this.searchTrigger.searchClearChan$.subscribe(clear => { this.closeSub = this.searchTrigger.searchClearChan$.subscribe(clear => {
this.searchTerm = ""; this.searchTerm = "";
}); });
if(this.appConfigService.isIntegrationMode()){
this.placeholderText = "GLOBAL_SEARCH.PLACEHOLDER_VIC";
}
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@ -7,7 +7,7 @@ import { modalEvents } from '../modal-events.const';
import { SessionUser } from '../../shared/session-user'; import { SessionUser } from '../../shared/session-user';
import { SessionService } from '../../shared/session.service'; import { SessionService } from '../../shared/session.service';
import { CookieService } from 'angular2-cookie/core'; import { CookieService, CookieOptions } from 'angular2-cookie/core';
import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../shared/shared.const'; import { supportedLangs, enLang, languageNames, CommonRoutes } from '../../shared/shared.const';
import { AppConfigService } from '../../app-config.service'; import { AppConfigService } from '../../app-config.service';
@ -44,7 +44,8 @@ export class NavigatorComponent implements OnInit {
this.translate.onLangChange.subscribe(langChange => { this.translate.onLangChange.subscribe(langChange => {
this.selectedLang = langChange.lang; this.selectedLang = langChange.lang;
//Keep in cookie for next use //Keep in cookie for next use
this.cookie.put("harbor-lang", langChange.lang); let opt = new CookieOptions({path: '/', expires: new Date(Date.now() + 3600*1000*24*31)});
this.cookie.put("harbor-lang", langChange.lang, opt);
}); });
if (this.appConfigService.isIntegrationMode()) { if (this.appConfigService.isIntegrationMode()) {
this.appTitle = 'APP_TITLE.VIC'; this.appTitle = 'APP_TITLE.VIC';
@ -126,16 +127,14 @@ export class NavigatorComponent implements OnInit {
//Switch languages //Switch languages
switchLanguage(lang: string): void { switchLanguage(lang: string): void {
let selectedLang: string = enLang;//Default
if (supportedLangs.find(supportedLang => supportedLang === lang.trim())) { if (supportedLangs.find(supportedLang => supportedLang === lang.trim())) {
this.translate.use(lang); selectedLang = lang;
} else { } else {
this.translate.use(enLang);//Use default console.error('Language ' + lang.trim() + ' is not suppoted yet');
//TODO:
console.error('Language ' + lang.trim() + ' is not suppoted');
} }
setTimeout(() => {
window.location.reload(); this.translate.use(selectedLang).subscribe(() => window.location.reload());
}, 500);
} }
//Handle the home action //Handle the home action

View File

@ -86,7 +86,8 @@
"ROOT_CERT": "Download Root Cert" "ROOT_CERT": "Download Root Cert"
}, },
"GLOBAL_SEARCH": { "GLOBAL_SEARCH": {
"PLACEHOLDER": "Search Harbor..." "PLACEHOLDER": "Search Harbor...",
"PLACEHOLDER_VIC": "Search Registry..."
}, },
"SIDE_NAV": { "SIDE_NAV": {
"DASHBOARD": "Dashboard", "DASHBOARD": "Dashboard",

View File

@ -86,7 +86,8 @@
"ROOT_CERT": "下载根证书" "ROOT_CERT": "下载根证书"
}, },
"GLOBAL_SEARCH": { "GLOBAL_SEARCH": {
"PLACEHOLDER": "搜索 Harbor..." "PLACEHOLDER": "搜索 Harbor...",
"PLACEHOLDER_VIC": "搜索 Registry..."
}, },
"SIDE_NAV": { "SIDE_NAV": {
"DASHBOARD": "仪表板", "DASHBOARD": "仪表板",

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Harbor</title> <title>VMware</title>
<base href="/"> <base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico?v=2"> <link rel="icon" type="image/x-icon" href="favicon.ico?v=2">