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:
josephschorr 2017-11-08 16:18:13 -05:00 committed by GitHub
commit ada8cea447
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 17 deletions

View file

@ -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;
}

View file

@ -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;
}]);