Keep appstore url bar up-to-date with the selected app

This allows sharing links directly

Fixes #526
This commit is contained in:
Johannes Zellner
2016-01-25 16:21:41 +01:00
parent 7a71315d33
commit 61c2ce0f47
2 changed files with 48 additions and 27 deletions

View File

@@ -176,7 +176,7 @@
<div class="col-md-10" ng-show="ready && apps.length">
<div class="row-no-margin">
<div class="col-sm-1 appstore-item" ng-repeat="app in apps">
<div class="appstore-item-content highlight" ng-click="showInstall(app)" ng-class="{ 'appstore-item-content-testing': (app.publishState === 'testing' || app.publishState === 'pending_approval') }">
<div class="appstore-item-content highlight" ng-click="gotoApp(app)" ng-class="{ 'appstore-item-content-testing': (app.publishState === 'testing' || app.publishState === 'pending_approval') }">
<span class="badge badge-danger appstore-item-badge-testing" ng-show="app.publishState === 'testing'">Testing</span>
<span class="badge badge-warning appstore-item-badge-testing" ng-show="app.publishState === 'pending_approval'">Pending Approval</span>
<div class="appstore-item-content-icon col-same-height">

View File

@@ -293,7 +293,42 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
});
};
function refresh() {
$scope.gotoApp = function (app) {
$location.path('/appstore/' + app.manifest.id, false).search({ version : app.manifest.version });
};
function hashChangeListener() {
var appId = $location.path().slice('/appstore/'.length);
var version = $location.search().version;
if (appId) {
if (version) {
AppStore.getAppByIdAndVersion(appId, version, function (error, result) {
if (error) {
$scope.showAppNotFound(appId, version);
console.error(error);
return;
}
$scope.showInstall(result);
});
} else {
var found = $scope.apps.filter(function (app) {
return (app.id === appId) && (version ? version === app.manifest.version : true);
});
if (found.length) {
$scope.showInstall(found[0]);
} else {
$scope.showAppNotFound(appId, null);
}
}
} else {
$scope.reset();
}
}
(function refresh() {
$scope.ready = false;
Client.getUsers(function (error, users) {
@@ -313,36 +348,22 @@ angular.module('Application').controller('AppStoreController', ['$scope', '$loca
$scope.apps = apps;
// show install app dialog immediately if an app id was passed in the query
if ($routeParams.appId) {
if ($routeParams.version) {
AppStore.getAppByIdAndVersion($routeParams.appId, $routeParams.version, function (error, result) {
if (error) {
$scope.showAppNotFound($routeParams.appId, $routeParams.version);
console.error(error);
return;
}
$scope.showInstall(result);
});
} else {
var found = apps.filter(function (app) {
return (app.id === $routeParams.appId) && ($routeParams.version ? $routeParams.version === app.manifest.version : true);
});
if (found.length) {
$scope.showInstall(found[0]);
} else {
$scope.showAppNotFound($routeParams.appId, null);
}
}
}
hashChangeListener();
$scope.ready = true;
});
});
}
})();
refresh();
$('#appInstallModal').on('hide.bs.modal', function () {
$location.path('/appstore', false).search({ version: undefined });
});
window.addEventListener('hashchange', hashChangeListener);
$scope.$on('$destroy', function handler() {
window.removeEventListener('hashchange', hashChangeListener);
});
// setup all the dialog focus handling
['appInstallModal', 'feedbackModal'].forEach(function (id) {