{{ note.content | characters:200:false }}
+diff --git a/database/db.js b/database/db.js
index 305fb6a..86bb90f 100644
--- a/database/db.js
+++ b/database/db.js
@@ -942,4 +942,33 @@ db.hotBookmarks = function(date) {
});
};
+db.addNote = function(note) {
+ var sql = "INSERT INTO `notes` (`user_id`, `content`, `tag_id`) VALUES ('"+ note.user_id +"', "+ client.escape(note.content) +", '"+ note.tag_id +"')";
+ console.log(sql);
+
+ return new Promise(function(resolve, reject) {
+ client.query(sql, (err, result) => {
+ if (err) {
+ reject(err);
+ } else {
+ resolve(result.insertId);
+ }
+ });
+ });
+};
+
+db.getNotes = function(params) {
+ var sql = "SELECT notes.id, notes.content, notes.tag_id, DATE_FORMAT(notes.created_at, '%Y-%m-%d %H:%i:%s') as created_at, tags.name FROM `notes` LEFT JOIN tags ON tags.id = notes.tag_id WHERE notes.user_id = '"+params.user_id+"' ORDER BY `created_at` DESC";
+ console.log(sql);
+ return new Promise(function(resolve, reject) {
+ client.query(sql, (err, result) => {
+ if (err) {
+ reject(err);
+ } else {
+ resolve(result);
+ }
+ });
+ });
+};
+
module.exports = db;
diff --git a/public/index.html b/public/index.html
index ab94130..86b4b53 100644
--- a/public/index.html
+++ b/public/index.html
@@ -69,6 +69,7 @@
+
diff --git a/public/scripts/app-angular.js b/public/scripts/app-angular.js
index 9cdd3cb..907204d 100644
--- a/public/scripts/app-angular.js
+++ b/public/scripts/app-angular.js
@@ -24,6 +24,11 @@ app.config(function($stateProvider, $urlRouterProvider, $httpProvider) {
templateUrl: '/views/praise.html',
controller: 'praiseCtr'
})
+ .state('note', {
+ url: '/note',
+ templateUrl: '/views/note.html',
+ controller: 'noteCtr'
+ })
.state('search', {
url: '/search',
templateUrl: '/views/search.html',
diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js
index 3cffde2..2c9a6ac 100644
--- a/public/scripts/controllers/menus-controller.js
+++ b/public/scripts/controllers/menus-controller.js
@@ -34,6 +34,9 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time
}, {
uiSref: 'praise',
title: '赞赏'
+ }, {
+ uiSref: 'note',
+ title: '备忘录'
}];
// 未登陆显示的菜单数据
diff --git a/public/scripts/controllers/note-controller.js b/public/scripts/controllers/note-controller.js
new file mode 100644
index 0000000..e8231d5
--- /dev/null
+++ b/public/scripts/controllers/note-controller.js
@@ -0,0 +1,127 @@
+app.controller('noteCtr', ['$scope', '$state', '$stateParams', '$filter', '$window', '$timeout', 'ngDialog', 'bookmarkService', 'pubSubService', function($scope, $state, $stateParams, $filter, $window, $timeout, ngDialog, bookmarkService, pubSubService) {
+ console.log("Hello noteCtr...", $stateParams);
+
+ $scope.loadBusy = false;
+ $scope.edit = false;
+ $scope.content = '';
+ $scope.notes = [];
+
+ bookmarkService.autoLogin()
+ .then((data) => {
+ var login = data.logined;
+ var index = login ? 6 : 1;
+ pubSubService.publish('Common.menuActive', {
+ login: login,
+ index: index
+ });
+ getNotes();
+ })
+ .catch((err) => {
+ console.log('autoLogin err', err)
+ });
+
+ $scope.showAddNote = function(){
+ $scope.edit = (!$scope.edit);
+ updateEditPos();
+ }
+
+ $scope.addNote = function(close){
+ $scope.edit = close;
+ var note = {
+ tag_id: -1,
+ content: $scope.content,
+ }
+
+ bookmarkService.addNote(note)
+ .then((data) => {
+ console.log(JSON.stringify(data));
+ $scope.content = '';
+ getNotes();
+ })
+ .catch((err) => {
+ console.log('addNote err', err)
+ });
+ }
+
+ $scope.copy = function(id, content){
+ console.log("copy note.....");
+ var showContent = content.length >= 180 ? content.substr(0, 180)+'...' : content;
+ var clipboard = new Clipboard("#noteid"+id, {
+ text: function() {
+ return content;
+ }
+ });
+
+ clipboard.on('success', function(e) {
+ toastr.success(showContent + '
已复制到您的剪切板', "提示");
+ clipboard.destroy();
+ });
+
+ clipboard.on('error', function(e) {
+ toastr.error(showContent + '
复制失败', "提示");
+ clipboard.destroy();
+ });
+ }
+
+ $scope.delNote = function(id){
+ toastr.warning('暂未实现', "提示");
+ }
+
+ $scope.editNote = function(id){
+ toastr.warning('暂未实现', "提示");
+ }
+
+ $scope.detailNote = function(id){
+ toastr.warning('暂未实现', "提示");
+ }
+ // $('.js-segment-praise').transition('hide');
+ function getNotes(){
+ var params = {};
+ bookmarkService.getNotes(params)
+ .then((data) => {
+ $scope.notes = data;
+ })
+ .catch((err) => {
+ $scope.notes = [];
+ });
+ }
+
+ function animation() {
+ var data = ['scale', 'fade', 'fade up', 'fade down', 'fade left', 'fade right', 'horizontal flip',
+ 'vertical flip', 'drop', 'fly left', 'fly right', 'fly up', 'fly down',
+ 'browse', 'browse right', 'slide down', 'slide up', 'slide left', 'slide right'
+ ];
+ var t = data[parseInt(Math.random() * 1000) % data.length];
+
+ return t;
+ }
+
+ function transition() {
+ var className = 'js-note-card';
+ $('.' + className).transition('hide');
+ $('.' + className).transition({
+ animation: animation(),
+ duration: 500,
+ });
+ }
+ // TODO: 我要将编辑按钮固定在容器的右上角
+ $(window).resize(updateEditPos);
+ updateEditPos();
+
+ function updateEditPos() {
+ for (var i = 1; i <= 100; i += 10) {
+ setTimeout(function() {
+ var offset = $('.js-note-card').offset();
+ if (offset) {
+ var t = offset.top;
+ var l = offset.left;
+ var w = $('.js-note-card').width();
+ $('.js-note-add').offset({
+ top: t + 10,
+ left: l + w - 10,
+ })
+ }
+ }, 100 * i)
+ }
+ }
+}]);
diff --git a/public/scripts/controllers/tags-controller.js b/public/scripts/controllers/tags-controller.js
index 5c487d5..3476570 100644
--- a/public/scripts/controllers/tags-controller.js
+++ b/public/scripts/controllers/tags-controller.js
@@ -480,7 +480,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$window', '$stateParams', '$tim
var t = offset.top;
var l = offset.left;
var w = $('.js-tags').width();
- $('.js-edit').offset({
+ $('.js-note-add').offset({
top: t + 10,
left: l + w - 10,
})
diff --git a/public/scripts/directives/js-init-directive.js b/public/scripts/directives/js-init-directive.js
index 8e159dc..3b85471 100644
--- a/public/scripts/directives/js-init-directive.js
+++ b/public/scripts/directives/js-init-directive.js
@@ -230,3 +230,52 @@ app.filter('searchType', function() {
return types[type];
}
});
+
+app.filter('characters', function () {
+ return function (input, chars, breakOnWord) {
+ if (isNaN(chars)) return input;
+ if (chars <= 0) return '';
+ if (input && input.length > chars) {
+ input = input.substring(0, chars);
+
+ if (!breakOnWord) {
+ var lastspace = input.lastIndexOf(' ');
+ //get last space
+ if (lastspace !== -1) {
+ input = input.substr(0, lastspace);
+ }
+ }else{
+ while(input.charAt(input.length-1) === ' '){
+ input = input.substr(0, input.length -1);
+ }
+ }
+ return input + '…';
+ }
+ return input;
+ };
+})
+.filter('splitcharacters', function() {
+ return function (input, chars) {
+ if (isNaN(chars)) return input;
+ if (chars <= 0) return '';
+ if (input && input.length > chars) {
+ var prefix = input.substring(0, chars/2);
+ var postfix = input.substring(input.length-chars/2, input.length);
+ return prefix + '...' + postfix;
+ }
+ return input;
+ };
+})
+.filter('words', function () {
+ return function (input, words) {
+ if (isNaN(words)) return input;
+ if (words <= 0) return '';
+ if (input) {
+ var inputWords = input.split(/\s+/);
+ if (inputWords.length > words) {
+ input = inputWords.slice(0, words).join(' ') + '…';
+ }
+ }
+ return input;
+ };
+});
diff --git a/public/scripts/services/bookmark-service.js b/public/scripts/services/bookmark-service.js
index 0242d9b..b4c6d8b 100644
--- a/public/scripts/services/bookmark-service.js
+++ b/public/scripts/services/bookmark-service.js
@@ -326,7 +326,7 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
});
return def.promise;
},
- getAdvices: function getAdvices(params) {
+ getAdvices: function(params) {
var def = $q.defer();
$http.get('/api/advices/', {
params: params
@@ -366,6 +366,32 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
});
return def.promise;
},
+ addNote: function(params) {
+ var def = $q.defer();
+ $http.post('/api/addNote/', {
+ params: params
+ })
+ .success(function(data) {
+ def.resolve(data);
+ })
+ .error(function(data, status) {
+ def.reject('addNote error');
+ });
+ return def.promise;
+ },
+ getNotes: function(params) {
+ var def = $q.defer();
+ $http.get('/api/notes/', {
+ params: params
+ })
+ .success(function(data) {
+ def.resolve(data);
+ })
+ .error(function(data) {
+ def.reject('getNotes error');
+ });
+ return def.promise;
+ },
};
return service;
diff --git a/public/views/note.html b/public/views/note.html
new file mode 100644
index 0000000..dadc27d
--- /dev/null
+++ b/public/views/note.html
@@ -0,0 +1,42 @@
+
{{ note.content | characters:200:false }}
+
+