From 0d5da491753d423dd15a6a2960ee2f68ccd3769a Mon Sep 17 00:00:00 2001 From: kunw Date: Fri, 15 Apr 2016 01:50:10 +0800 Subject: [PATCH] refined structure for UI development --- static/ng/resources/css/repository.css | 2 +- .../navigation-details.directive.html | 5 +++ .../components/navigation-tab.directive.html | 3 +- .../js/components/navigation-tab.directive.js | 45 ++++++++++++------- static/ng/resources/js/harbor.constants.js | 10 +---- static/ng/resources/js/harbor.initialize.js | 20 +-------- static/ng/resources/js/harbor.module.js | 4 +- .../js/header/navigation.controllers.js | 17 ------- static/ng/resources/js/index/index.data.js | 7 --- static/ng/resources/js/index/index.module.js | 6 --- .../details/details.module.js} | 4 +- .../js/{ => layout}/header/header.data.js | 0 .../js/{ => layout}/header/header.module.js | 0 .../{ => layout}/log/list-log.controller.js | 0 .../js/{ => layout}/log/log.module.js | 0 .../project/add-project.controller.js | 0 .../project/list-project.controller.js | 0 .../js/{ => layout}/project/project.module.js | 0 .../add-projectmember.controller.js | 0 .../delete-projectmember.controller.js | 0 .../edit-projectmember.controller.js | 0 .../projectmember/projectmember.module.js | 0 .../delete-repository.controller.js | 0 .../repository/list-repository.controller.js | 0 .../repository/repository.module.js | 0 .../{ => layout}/search/search.controller.js | 0 .../js/{ => layout}/search/search.module.js | 0 .../user/change-password.controller.js | 0 .../user/delete-user.controller.js | 0 .../user/forgot-password.controller.js | 0 .../{ => layout}/user/list-user.controller.js | 0 .../{ => layout}/user/sign-in.controller.js | 0 .../{ => layout}/user/sign-up.controller.js | 0 .../js/{ => layout}/user/user.module.js | 0 .../ng/resources/js/services/services.data.js | 8 ---- .../js/session/session.current-user.js | 38 ++++++++++++++++ .../ng/resources/js/session/session.module.js | 10 +++++ views/ng/dashboard.htm | 2 +- views/ng/repository.htm | 18 ++++---- views/ng/sections/headerContent.htm | 4 +- views/ng/sections/headerInclude.htm | 8 ++-- 41 files changed, 111 insertions(+), 100 deletions(-) create mode 100644 static/ng/resources/js/components/navigation-details.directive.html delete mode 100644 static/ng/resources/js/header/navigation.controllers.js delete mode 100644 static/ng/resources/js/index/index.data.js delete mode 100644 static/ng/resources/js/index/index.module.js rename static/ng/resources/js/{services/services.module.js => layout/details/details.module.js} (53%) rename static/ng/resources/js/{ => layout}/header/header.data.js (100%) rename static/ng/resources/js/{ => layout}/header/header.module.js (100%) rename static/ng/resources/js/{ => layout}/log/list-log.controller.js (100%) rename static/ng/resources/js/{ => layout}/log/log.module.js (100%) rename static/ng/resources/js/{ => layout}/project/add-project.controller.js (100%) rename static/ng/resources/js/{ => layout}/project/list-project.controller.js (100%) rename static/ng/resources/js/{ => layout}/project/project.module.js (100%) rename static/ng/resources/js/{ => layout}/projectmember/add-projectmember.controller.js (100%) rename static/ng/resources/js/{ => layout}/projectmember/delete-projectmember.controller.js (100%) rename static/ng/resources/js/{ => layout}/projectmember/edit-projectmember.controller.js (100%) rename static/ng/resources/js/{ => layout}/projectmember/projectmember.module.js (100%) rename static/ng/resources/js/{ => layout}/repository/delete-repository.controller.js (100%) rename static/ng/resources/js/{ => layout}/repository/list-repository.controller.js (100%) rename static/ng/resources/js/{ => layout}/repository/repository.module.js (100%) rename static/ng/resources/js/{ => layout}/search/search.controller.js (100%) rename static/ng/resources/js/{ => layout}/search/search.module.js (100%) rename static/ng/resources/js/{ => layout}/user/change-password.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/delete-user.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/forgot-password.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/list-user.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/sign-in.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/sign-up.controller.js (100%) rename static/ng/resources/js/{ => layout}/user/user.module.js (100%) delete mode 100644 static/ng/resources/js/services/services.data.js create mode 100644 static/ng/resources/js/session/session.current-user.js create mode 100644 static/ng/resources/js/session/session.module.js diff --git a/static/ng/resources/css/repository.css b/static/ng/resources/css/repository.css index fa5331040..8debca562 100644 --- a/static/ng/resources/css/repository.css +++ b/static/ng/resources/css/repository.css @@ -32,7 +32,7 @@ list-style-type: none; } -.switch-pane-tabs a, .switch-pane-tabs span { +.switch-pane-tabs a,.switch-pane-tabs span { display: inline-block; text-decoration: none; float: left; diff --git a/static/ng/resources/js/components/navigation-details.directive.html b/static/ng/resources/js/components/navigation-details.directive.html new file mode 100644 index 000000000..16f289e4b --- /dev/null +++ b/static/ng/resources/js/components/navigation-details.directive.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/static/ng/resources/js/components/navigation-tab.directive.html b/static/ng/resources/js/components/navigation-tab.directive.html index 9bbfedc82..bd1785d58 100644 --- a/static/ng/resources/js/components/navigation-tab.directive.html +++ b/static/ng/resources/js/components/navigation-tab.directive.html @@ -1,3 +1,4 @@ \ No newline at end of file diff --git a/static/ng/resources/js/components/navigation-tab.directive.js b/static/ng/resources/js/components/navigation-tab.directive.js index a8c6e6b55..27adeff31 100644 --- a/static/ng/resources/js/components/navigation-tab.directive.js +++ b/static/ng/resources/js/components/navigation-tab.directive.js @@ -8,29 +8,42 @@ function navigationTab() { var directive = { - restrict: 'EA', - scope: { - "tabs": "=" - }, - - templateUrl: '/static/ng/resources/js/components/navigation-tab.directive.html', - link: link + restrict: 'E', + templateUrl: getTemplateUrl, + link: link, + controller: controller } return directive; - function link(scope, element, attrs) { - element - .on('mouseover', mouseover) - .on('mouseout', mouseout); + function getTemplateUrl(element, attrs) { + return '/static/ng/resources/js/components/'+ attrs.templateUrl; + } + + function link(scope, element, attrs, ctrl) { + + if (attrs.templateUrl.indexOf("navigation-tab") >= 0) { + element.find('a[href$="' + ctrl.location + '"]').addClass('active'); + } + + if (attrs.templateUrl.indexOf("navigation-details") >= 0) { + element.find('a:first').addClass('active'); + } - function mouseover(event) { + element.on('click', click); + + function click(event) { + element.find('a').removeClass('active'); $(event.target).addClass('active'); } - - function mouseout(event) { - $(event.target).removeClass('active'); - } + + } + + controller.$inject = ['$window']; + + function controller($window) { + var vm = this; + vm.location = $window.location.pathname; } } diff --git a/static/ng/resources/js/harbor.constants.js b/static/ng/resources/js/harbor.constants.js index 7e4af9aec..afd3a0be9 100644 --- a/static/ng/resources/js/harbor.constants.js +++ b/static/ng/resources/js/harbor.constants.js @@ -2,14 +2,6 @@ 'use strict'; angular - .module('harbor.app') - .constant('navigationTabs', navigationTabs); - - function navigationTabs() { - var data = [ - {name: "Dashboard", url: "/ng/dashboard"}, - {name: "My Projects", url: "/ng/project"}]; - return data; - } + .module('harbor.app'); })(); \ No newline at end of file diff --git a/static/ng/resources/js/harbor.initialize.js b/static/ng/resources/js/harbor.initialize.js index 43f9a7b89..3e1ee413b 100644 --- a/static/ng/resources/js/harbor.initialize.js +++ b/static/ng/resources/js/harbor.initialize.js @@ -2,24 +2,6 @@ 'use strict'; angular - .module('harbor.app') - .run(CurrentUser); - - CurrentUser.$inject = ['CurrentUserService', '$log']; - - function CurrentUser(CurrentUserService, $log) { + .module('harbor.app'); - CurrentUserService() - .then(getCurrentUserComplete) - .catch(getCurrentUserFailed); - - function getCurrentUserComplete(data) { - $log.info(data.data); - } - - function getCurrentUserFailed(e){ - $log.info(e); - } - - } })(); \ No newline at end of file diff --git a/static/ng/resources/js/harbor.module.js b/static/ng/resources/js/harbor.module.js index 6ec1ab332..b31d2d06c 100644 --- a/static/ng/resources/js/harbor.module.js +++ b/static/ng/resources/js/harbor.module.js @@ -3,6 +3,8 @@ angular .module('harbor.app', [ 'harbor.services.user', + 'harbor.session', 'harbor.header', - 'harbor.index']); + 'harbor.details' + ]); })(); \ No newline at end of file diff --git a/static/ng/resources/js/header/navigation.controllers.js b/static/ng/resources/js/header/navigation.controllers.js deleted file mode 100644 index 52f26f72a..000000000 --- a/static/ng/resources/js/header/navigation.controllers.js +++ /dev/null @@ -1,17 +0,0 @@ -(function() { - - 'use strict'; - - angular - .module('harbor.header') - .controller('NavigationController', NavigationController); - - NavigationController.$inject = ['navigationTabs']; - - - function NavigationController(navigationTabs) { - var vm = this; - vm.tabs = navigationTabs(); - } - -})(); \ No newline at end of file diff --git a/static/ng/resources/js/index/index.data.js b/static/ng/resources/js/index/index.data.js deleted file mode 100644 index 2ea337eae..000000000 --- a/static/ng/resources/js/index/index.data.js +++ /dev/null @@ -1,7 +0,0 @@ -(function() { - - 'use strict'; - - angular - .module('harbor.index'); -})(); \ No newline at end of file diff --git a/static/ng/resources/js/index/index.module.js b/static/ng/resources/js/index/index.module.js deleted file mode 100644 index 73346f241..000000000 --- a/static/ng/resources/js/index/index.module.js +++ /dev/null @@ -1,6 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('harbor.index', []); -})(); \ No newline at end of file diff --git a/static/ng/resources/js/services/services.module.js b/static/ng/resources/js/layout/details/details.module.js similarity index 53% rename from static/ng/resources/js/services/services.module.js rename to static/ng/resources/js/layout/details/details.module.js index 394d71d9d..0651d2749 100644 --- a/static/ng/resources/js/services/services.module.js +++ b/static/ng/resources/js/layout/details/details.module.js @@ -1,6 +1,8 @@ (function() { + 'use strict'; angular - .module('harbor.services', []); + .module('harbor.details', []); + })(); \ No newline at end of file diff --git a/static/ng/resources/js/header/header.data.js b/static/ng/resources/js/layout/header/header.data.js similarity index 100% rename from static/ng/resources/js/header/header.data.js rename to static/ng/resources/js/layout/header/header.data.js diff --git a/static/ng/resources/js/header/header.module.js b/static/ng/resources/js/layout/header/header.module.js similarity index 100% rename from static/ng/resources/js/header/header.module.js rename to static/ng/resources/js/layout/header/header.module.js diff --git a/static/ng/resources/js/log/list-log.controller.js b/static/ng/resources/js/layout/log/list-log.controller.js similarity index 100% rename from static/ng/resources/js/log/list-log.controller.js rename to static/ng/resources/js/layout/log/list-log.controller.js diff --git a/static/ng/resources/js/log/log.module.js b/static/ng/resources/js/layout/log/log.module.js similarity index 100% rename from static/ng/resources/js/log/log.module.js rename to static/ng/resources/js/layout/log/log.module.js diff --git a/static/ng/resources/js/project/add-project.controller.js b/static/ng/resources/js/layout/project/add-project.controller.js similarity index 100% rename from static/ng/resources/js/project/add-project.controller.js rename to static/ng/resources/js/layout/project/add-project.controller.js diff --git a/static/ng/resources/js/project/list-project.controller.js b/static/ng/resources/js/layout/project/list-project.controller.js similarity index 100% rename from static/ng/resources/js/project/list-project.controller.js rename to static/ng/resources/js/layout/project/list-project.controller.js diff --git a/static/ng/resources/js/project/project.module.js b/static/ng/resources/js/layout/project/project.module.js similarity index 100% rename from static/ng/resources/js/project/project.module.js rename to static/ng/resources/js/layout/project/project.module.js diff --git a/static/ng/resources/js/projectmember/add-projectmember.controller.js b/static/ng/resources/js/layout/projectmember/add-projectmember.controller.js similarity index 100% rename from static/ng/resources/js/projectmember/add-projectmember.controller.js rename to static/ng/resources/js/layout/projectmember/add-projectmember.controller.js diff --git a/static/ng/resources/js/projectmember/delete-projectmember.controller.js b/static/ng/resources/js/layout/projectmember/delete-projectmember.controller.js similarity index 100% rename from static/ng/resources/js/projectmember/delete-projectmember.controller.js rename to static/ng/resources/js/layout/projectmember/delete-projectmember.controller.js diff --git a/static/ng/resources/js/projectmember/edit-projectmember.controller.js b/static/ng/resources/js/layout/projectmember/edit-projectmember.controller.js similarity index 100% rename from static/ng/resources/js/projectmember/edit-projectmember.controller.js rename to static/ng/resources/js/layout/projectmember/edit-projectmember.controller.js diff --git a/static/ng/resources/js/projectmember/projectmember.module.js b/static/ng/resources/js/layout/projectmember/projectmember.module.js similarity index 100% rename from static/ng/resources/js/projectmember/projectmember.module.js rename to static/ng/resources/js/layout/projectmember/projectmember.module.js diff --git a/static/ng/resources/js/repository/delete-repository.controller.js b/static/ng/resources/js/layout/repository/delete-repository.controller.js similarity index 100% rename from static/ng/resources/js/repository/delete-repository.controller.js rename to static/ng/resources/js/layout/repository/delete-repository.controller.js diff --git a/static/ng/resources/js/repository/list-repository.controller.js b/static/ng/resources/js/layout/repository/list-repository.controller.js similarity index 100% rename from static/ng/resources/js/repository/list-repository.controller.js rename to static/ng/resources/js/layout/repository/list-repository.controller.js diff --git a/static/ng/resources/js/repository/repository.module.js b/static/ng/resources/js/layout/repository/repository.module.js similarity index 100% rename from static/ng/resources/js/repository/repository.module.js rename to static/ng/resources/js/layout/repository/repository.module.js diff --git a/static/ng/resources/js/search/search.controller.js b/static/ng/resources/js/layout/search/search.controller.js similarity index 100% rename from static/ng/resources/js/search/search.controller.js rename to static/ng/resources/js/layout/search/search.controller.js diff --git a/static/ng/resources/js/search/search.module.js b/static/ng/resources/js/layout/search/search.module.js similarity index 100% rename from static/ng/resources/js/search/search.module.js rename to static/ng/resources/js/layout/search/search.module.js diff --git a/static/ng/resources/js/user/change-password.controller.js b/static/ng/resources/js/layout/user/change-password.controller.js similarity index 100% rename from static/ng/resources/js/user/change-password.controller.js rename to static/ng/resources/js/layout/user/change-password.controller.js diff --git a/static/ng/resources/js/user/delete-user.controller.js b/static/ng/resources/js/layout/user/delete-user.controller.js similarity index 100% rename from static/ng/resources/js/user/delete-user.controller.js rename to static/ng/resources/js/layout/user/delete-user.controller.js diff --git a/static/ng/resources/js/user/forgot-password.controller.js b/static/ng/resources/js/layout/user/forgot-password.controller.js similarity index 100% rename from static/ng/resources/js/user/forgot-password.controller.js rename to static/ng/resources/js/layout/user/forgot-password.controller.js diff --git a/static/ng/resources/js/user/list-user.controller.js b/static/ng/resources/js/layout/user/list-user.controller.js similarity index 100% rename from static/ng/resources/js/user/list-user.controller.js rename to static/ng/resources/js/layout/user/list-user.controller.js diff --git a/static/ng/resources/js/user/sign-in.controller.js b/static/ng/resources/js/layout/user/sign-in.controller.js similarity index 100% rename from static/ng/resources/js/user/sign-in.controller.js rename to static/ng/resources/js/layout/user/sign-in.controller.js diff --git a/static/ng/resources/js/user/sign-up.controller.js b/static/ng/resources/js/layout/user/sign-up.controller.js similarity index 100% rename from static/ng/resources/js/user/sign-up.controller.js rename to static/ng/resources/js/layout/user/sign-up.controller.js diff --git a/static/ng/resources/js/user/user.module.js b/static/ng/resources/js/layout/user/user.module.js similarity index 100% rename from static/ng/resources/js/user/user.module.js rename to static/ng/resources/js/layout/user/user.module.js diff --git a/static/ng/resources/js/services/services.data.js b/static/ng/resources/js/services/services.data.js deleted file mode 100644 index 7c2aa400c..000000000 --- a/static/ng/resources/js/services/services.data.js +++ /dev/null @@ -1,8 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('harbor.services'); - - -})(); \ No newline at end of file diff --git a/static/ng/resources/js/session/session.current-user.js b/static/ng/resources/js/session/session.current-user.js new file mode 100644 index 000000000..36803a07c --- /dev/null +++ b/static/ng/resources/js/session/session.current-user.js @@ -0,0 +1,38 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.session') + .controller('CurrentUserController', CurrentUserController) + .directive('currentUser', currentUser); + + CurrentUserController.$inject = ['CurrentUserService', '$log', '$window']; + + function CurrentUserController(CurrentUserService, $log, $window) { + + CurrentUserService() + .then(getCurrentUserComplete) + .catch(getCurrentUserFailed); + + function getCurrentUserComplete(data) { + $log.info('login success'); + } + + function getCurrentUserFailed(e){ + if(e.status == 401) { + $window.location = '/ng'; + } + } + } + + function currentUser() { + var directive = { + restrict: 'A', + controller: CurrentUserController, + bindToController: true + } + return directive; + } + +})(); \ No newline at end of file diff --git a/static/ng/resources/js/session/session.module.js b/static/ng/resources/js/session/session.module.js new file mode 100644 index 000000000..d85e0cdd1 --- /dev/null +++ b/static/ng/resources/js/session/session.module.js @@ -0,0 +1,10 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.session', [ + 'harbor.services.user' + ]); + +})(); \ No newline at end of file diff --git a/views/ng/dashboard.htm b/views/ng/dashboard.htm index 71fdcecf0..052174efb 100644 --- a/views/ng/dashboard.htm +++ b/views/ng/dashboard.htm @@ -1,4 +1,4 @@ -
+
diff --git a/views/ng/repository.htm b/views/ng/repository.htm index 42609f67b..07addadcf 100644 --- a/views/ng/repository.htm +++ b/views/ng/repository.htm @@ -6,17 +6,19 @@
myrepo
-
    + + + +
+