diff --git a/app.js b/app.js index f0251e5..df9cbe1 100644 --- a/app.js +++ b/app.js @@ -19,7 +19,9 @@ app.set('view engine', 'ejs'); //app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); app.use(logger('dev')); app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ extended: false })); +app.use(bodyParser.urlencoded({ + extended: false +})); app.use(cookieParser()); app.use(express.static(path.join(__dirname, 'public'))); @@ -29,9 +31,9 @@ app.use('/users', users); // catch 404 and forward to error handler app.use(function(req, res, next) { - var err = new Error('Not Found'); - err.status = 404; - next(err); + var err = new Error('Not Found'); + err.status = 404; + next(err); }); // error handlers @@ -39,23 +41,23 @@ app.use(function(req, res, next) { // development error handler // will print stacktrace if (app.get('env') === 'development') { - app.use(function(err, req, res, next) { - res.status(err.status || 500); - res.render('error', { - message: err.message, - error: err + app.use(function(err, req, res, next) { + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: err + }); }); - }); } // production error handler // no stacktraces leaked to user app.use(function(err, req, res, next) { - res.status(err.status || 500); - res.render('error', { - message: err.message, - error: {} - }); + res.status(err.status || 500); + res.render('error', { + message: err.message, + error: {} + }); }); diff --git a/public/index.html b/public/index.html index 2115439..6789620 100644 --- a/public/index.html +++ b/public/index.html @@ -12,47 +12,14 @@
- + +
+
@@ -62,11 +29,11 @@ + - + - diff --git a/public/scripts/app-angular.js b/public/scripts/app-angular.js index f0d9aa3..04fab71 100644 --- a/public/scripts/app-angular.js +++ b/public/scripts/app-angular.js @@ -35,6 +35,10 @@ app.config(function($stateProvider, $urlRouterProvider) { url: '/intro', templateUrl: '/views/intro.html' }) + .state('search', { + url: '/search', + templateUrl: '/views/search.html' + }) .state('/', { url: '/', templateUrl: '/views/intro.html' diff --git a/public/scripts/controllers/bookmarks-controller.js b/public/scripts/controllers/bookmarks-controller.js index 2750c9d..e3656c6 100644 --- a/public/scripts/controllers/bookmarks-controller.js +++ b/public/scripts/controllers/bookmarks-controller.js @@ -1,18 +1,21 @@ app.controller('bookmarksCtr', ['$scope', '$filter', 'bookmarkService', 'pubSubService', function($scope, $filter, bookmarkService, pubSubService) { console.log("Hello bookmarksCtr..."); $scope.bookmarks = []; // 书签数据 - getBookmarks({ + var params = { s: 111, b: 222, i: 'lcq' - }); + } + getBookmarks(params); pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, data) { console.log('subscribe MenuCtr.bookmarks', data); + getBookmarks(data); }); pubSubService.subscribe('MenuCtr.searchBookmarks', $scope, function(event, data) { - console.log(data); + console.log('subscribe MenuCtr.searchBookmarks', data); + getBookmarks(data); }); function getBookmarks(params) { diff --git a/public/scripts/controllers/edit-controller.js b/public/scripts/controllers/edit-controller.js index a67e3ed..45b0418 100644 --- a/public/scripts/controllers/edit-controller.js +++ b/public/scripts/controllers/edit-controller.js @@ -1,7 +1,13 @@ app.controller('editCtr', ['$scope', '$state', function($scope, $state) { + semanticInit(); - $scope.addTag = function(){ + $scope.addTag = function() { console.log('Hello , you have click add tag btn......') } + function semanticInit() { + $('.ui.dropdown').dropdown({ + forceSelection: false, + }); + } }]); diff --git a/public/scripts/controllers/menu-controller.js b/public/scripts/controllers/menu-controller.js deleted file mode 100644 index 1e47038..0000000 --- a/public/scripts/controllers/menu-controller.js +++ /dev/null @@ -1,62 +0,0 @@ -app.controller('menuCtr', ['$scope', '$state', 'pubSubService', function($scope, $state, pubSubService) { - $scope.login = true; /**< 是否登陆 */ - $scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */ - $scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */ - if ($scope.login) { - setTimeout(()=>{$state.go('bookmarks')},0); - } - - - /** - * @todo http://stackoverflow.com/questions/31449948/ui-router-state-go-not-working - */ - if($scope.login){ - setTimeout(()=>{ $state.go('bookmarks') }, 0); - } - - // 登陆之后显示的菜单数据。uiSerf:内部跳转链接。 - $scope.loginMenus = [ - {uiSref:'bookmarks', title:'书签'}, - {uiSref:'tags', title:'书签分类'}, - {uiSref:'advice', title:'建议'}, - {uiSref:'settings', title:'设置'}, - {uiSref:'intro', title:'说明'} - ]; - - // 未登陆显示的菜单数据 - $scope.notLoginMenus = [ - {uiSref:'intro', title:'说明'}, - {uiSref:'register', title:'注册'} - ]; - - /** - * @func - * @desc 根据点击的菜单,更新选择的索引 - * @param {number} index - 点击的索引 - * @param {bool} login - 登陆标志 - */ - $scope.selectMenu = function(index, login){ - var msg = 'MenuCtr.'; - if (login) { - $scope.selectLoginIndex = index; - msg += $scope.loginMenus[index].uiSref; - } else { - $scope.selectNotLoginIndex = index; - msg += $scope.notLoginMenus[index].uiSref; - } - console.log(msg); - pubSubService.publish(msg); - } - - /** - * @func - * @desc 点击搜索按钮搜索书签 - */ - $scope.searchBookmarks = function(){ - pubSubService.publish('MenuCtr.searchBookmarks', {'key': 'JavaScript'}); - } - - $scope.showAddBookmarkMoadl = function(){ - $('.ui.modal.js-add-bookmark').modal('show'); - } -}]); diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js new file mode 100644 index 0000000..61bf7aa --- /dev/null +++ b/public/scripts/controllers/menus-controller.js @@ -0,0 +1,99 @@ +app.controller('menuCtr', ['$scope', '$state', 'pubSubService', function($scope, $state, pubSubService) { + $scope.login = true; /**< 是否登陆 */ + $scope.selectLoginIndex = 0; /**< 默认登陆之后的选择的菜单索引,下表从 0 开始 */ + $scope.selectNotLoginIndex = 0; /**< 默认未登陆之后的选择的菜单索引,下表从 0 开始 */ + $scope.keyword = ''; /**< 搜索关键字 */ + $scope.showSearchInput = true; /**< 是否显示输入搜索关键字的输入框 */ + if ($scope.login) { + setTimeout(() => { + $state.go('bookmarks') + }, 0); + } + semanticInit(); + + + /** + * @todo http://stackoverflow.com/questions/31449948/ui-router-state-go-not-working + */ + if ($scope.login) { + setTimeout(() => { + $state.go('bookmarks') + }, 0); + } + + // 登陆之后显示的菜单数据。uiSerf:内部跳转链接。 + $scope.loginMenus = [{ + uiSref: 'bookmarks', + title: '书签' + }, { + uiSref: 'tags', + title: '书签分类' + }, { + uiSref: 'advice', + title: '建议' + }, { + uiSref: 'settings', + title: '设置' + }, { + uiSref: 'intro', + title: '说明' + }]; + + // 未登陆显示的菜单数据 + $scope.notLoginMenus = [{ + uiSref: 'intro', + title: '说明' + }, { + uiSref: 'register', + title: '注册' + }]; + + /** + * @func + * @desc 根据点击的菜单,更新选择的索引 + * @param {number} index - 点击的索引 + * @param {bool} login - 登陆标志 + */ + $scope.selectMenu = function(index, login) { + var msg = 'MenuCtr.'; + if (login) { + $scope.selectLoginIndex = index; + msg += $scope.loginMenus[index].uiSref; + } else { + $scope.selectNotLoginIndex = index; + msg += $scope.notLoginMenus[index].uiSref; + } + console.log(msg); + pubSubService.publish(msg); + } + + /** + * @func + * @desc 点击搜索按钮搜索书签 + */ + $scope.searchBookmarks = function() { + console.log('searchBookmarks clicked...'); + pubSubService.publish('MenuCtr.searchBookmarks', { + 'keyword': $scope.keyword + }); + $scope.selectLoginIndex = 0; + } + + /** + * @func + * @desc 点击下拉列表详情搜索 + */ + $scope.searchDetail = function() { + $scope.showSearchInput = false; + pubSubService.publish('MenuCtr.searchDetail', { + 'key': 'JavaScript' + }); + } + $scope.showAddBookmarkMoadl = function() { + $('.ui.modal.js-add-bookmark').modal('show'); + } + + function semanticInit() { + $('.ui.dropdown').dropdown(); + } +}]); diff --git a/public/scripts/directive/edit-directive.js b/public/scripts/directive/edit-directive.js deleted file mode 100644 index 5498d4e..0000000 --- a/public/scripts/directive/edit-directive.js +++ /dev/null @@ -1,8 +0,0 @@ -app.directive('edit',function(){ - return { - restrict:'EAC', - templateUrl: '/views/bookmarks.html', - controller: 'bookmarksCtr', - replace:true - } -}); diff --git a/public/scripts/directives/edit-directive.js b/public/scripts/directives/edit-directive.js index 93ff99b..824729d 100644 --- a/public/scripts/directives/edit-directive.js +++ b/public/scripts/directives/edit-directive.js @@ -1,7 +1,7 @@ -app.directive('edit',function(){ +app.directive('edit', function() { return { - restrict:'EAC', + restrict: 'EAC', templateUrl: '/views/edit.html', - replace:true + replace: true } }); diff --git a/public/scripts/directives/menus-directive.js b/public/scripts/directives/menus-directive.js new file mode 100644 index 0000000..fd68afe --- /dev/null +++ b/public/scripts/directives/menus-directive.js @@ -0,0 +1,8 @@ +// 不要使用已有的html作为指令,如menu,否则angular会陷入死循环 +app.directive('menus', function() { + return { + restrict: 'EAC', + templateUrl: '/views/menus.html', + replace: true + } +}); diff --git a/public/scripts/semantic-init.js b/public/scripts/semantic-init.js deleted file mode 100644 index 2967df4..0000000 --- a/public/scripts/semantic-init.js +++ /dev/null @@ -1,3 +0,0 @@ - -// 下拉菜单初始化 -$('.ui.dropdown').dropdown(); diff --git a/public/views/menus.html b/public/views/menus.html new file mode 100644 index 0000000..325822f --- /dev/null +++ b/public/views/menus.html @@ -0,0 +1,36 @@ +
+ + +
diff --git a/public/views/search.html b/public/views/search.html new file mode 100644 index 0000000..c12308e --- /dev/null +++ b/public/views/search.html @@ -0,0 +1,3 @@ +

+ 这是详情搜索页 +