Merge pull request #2905 from coreos-inc/joseph.schorr/QS-50/repo-title
Fix handling of promises for title and description of pages in Quay
This commit is contained in:
commit
ada8cea447
2 changed files with 23 additions and 17 deletions
|
@ -103,9 +103,10 @@ export function provideRun($rootScope: QuayRunScope,
|
|||
|
||||
// Listen for route changes and update the title and description accordingly.
|
||||
$rootScope.$on('$routeChangeSuccess', async(event, current, previous) => {
|
||||
$rootScope.title = metaService.getTitle(current) || defaultTitle;
|
||||
|
||||
const title = await metaService.getTitle(current);
|
||||
const description = await metaService.getDescription(current);
|
||||
|
||||
$rootScope.title = title || defaultTitle;
|
||||
if ($rootScope.description != description) {
|
||||
$rootScope.description = description;
|
||||
}
|
||||
|
|
|
@ -17,27 +17,32 @@ angular.module('quay').factory('MetaService', ['$interpolate', '$timeout', funct
|
|||
return inter(page.scope);
|
||||
};
|
||||
|
||||
metaService.getTitle = function(page) {
|
||||
if (!page || !page.$$route) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var route = page.$$route;
|
||||
return interpolate(page, route && route.title);
|
||||
};
|
||||
|
||||
metaService.getDescription = function(page) {
|
||||
var interpolationPromise = function(page, fieldGetter) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!page || !page.$$route) {
|
||||
resolve(null);
|
||||
} else {
|
||||
// Timeout needed because page.scope is undefined
|
||||
$timeout(function() {
|
||||
resolve(interpolate(page, page.$$route.description));
|
||||
}, 10);
|
||||
return;
|
||||
}
|
||||
|
||||
if (page.scope) {
|
||||
resolve(interpolate(page, fieldGetter()));
|
||||
return;
|
||||
}
|
||||
|
||||
// Timeout needed because page.scope is initially undefined.
|
||||
$timeout(function() {
|
||||
resolve(interpolationPromise(page, fieldGetter));
|
||||
}, 10);
|
||||
});
|
||||
};
|
||||
|
||||
metaService.getTitle = function(page) {
|
||||
return interpolationPromise(page, () => page.$$route.title);
|
||||
};
|
||||
|
||||
metaService.getDescription = function(page) {
|
||||
return interpolationPromise(page, () => page.$$route.description);
|
||||
};
|
||||
|
||||
return metaService;
|
||||
}]);
|
||||
|
|
Reference in a new issue