增加了点击更新点击次数,最后一次点击数,分类如果是空过滤,排序显示按照分类总点击数
This commit is contained in:
parent
de8b327d4d
commit
230066b84b
|
|
@ -10,8 +10,11 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
|
||||||
show: $scope.showStyle,
|
show: $scope.showStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.jumpToUrl = function(url) {
|
$scope.jumpToUrl = function(url, id) {
|
||||||
$window.open(url, '_blank');
|
$window.open(url, '_blank');
|
||||||
|
bookmarkService.clickBookmark({
|
||||||
|
id: id
|
||||||
|
});
|
||||||
}
|
}
|
||||||
getBookmarks(params);
|
getBookmarks(params);
|
||||||
pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, params) {
|
pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, params) {
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,12 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
|
||||||
var params = [];
|
var params = [];
|
||||||
tags.forEach(function(tag) {
|
tags.forEach(function(tag) {
|
||||||
tag = tag.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, ' '); // 去除前后空格,多个空格转为一个空格;
|
tag = tag.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, ' '); // 去除前后空格,多个空格转为一个空格;
|
||||||
params.push(tag);
|
// 过滤是""的情况
|
||||||
|
if (tag) {
|
||||||
|
params.push(tag);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(params);
|
|
||||||
bookmarkService.addTags(params).then(
|
bookmarkService.addTags(params).then(
|
||||||
function(data) {
|
function(data) {
|
||||||
$scope.tags = data;
|
$scope.tags = data;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
|
||||||
});
|
});
|
||||||
return def.promise;
|
return def.promise;
|
||||||
},
|
},
|
||||||
|
clickBookmark: function(params) {
|
||||||
|
var def = $q.defer();
|
||||||
|
$http.post('/api/clickBookmark/', {
|
||||||
|
params: params
|
||||||
|
})
|
||||||
|
.success(function(data) {
|
||||||
|
def.resolve(data);
|
||||||
|
})
|
||||||
|
.error(function(data) {
|
||||||
|
console.log('Error: ' + data);
|
||||||
|
});
|
||||||
|
return def.promise;
|
||||||
|
},
|
||||||
logout: function(params) {
|
logout: function(params) {
|
||||||
var def = $q.defer();
|
var def = $q.defer();
|
||||||
$http.post('/api/logout/', {
|
$http.post('/api/logout/', {
|
||||||
|
|
@ -128,9 +141,9 @@ app.factory('AuthenticationService', function() {
|
||||||
return auth;
|
return auth;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.factory('TokenInterceptor', function ($q, $window, $location, AuthenticationService) {
|
app.factory('TokenInterceptor', function($q, $window, $location, AuthenticationService) {
|
||||||
return {
|
return {
|
||||||
request: function (config) {
|
request: function(config) {
|
||||||
config.headers = config.headers || {};
|
config.headers = config.headers || {};
|
||||||
if ($window.sessionStorage.token) {
|
if ($window.sessionStorage.token) {
|
||||||
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
|
config.headers.Authorization = 'Bearer ' + $window.sessionStorage.token;
|
||||||
|
|
@ -143,7 +156,7 @@ app.factory('TokenInterceptor', function ($q, $window, $location, Authentication
|
||||||
},
|
},
|
||||||
|
|
||||||
/* Set Authentication.isAuthenticated to true if 200 received */
|
/* Set Authentication.isAuthenticated to true if 200 received */
|
||||||
response: function (response) {
|
response: function(response) {
|
||||||
if (response != null && response.status == 200 && $window.sessionStorage.token && !AuthenticationService.isAuthenticated) {
|
if (response != null && response.status == 200 && $window.sessionStorage.token && !AuthenticationService.isAuthenticated) {
|
||||||
AuthenticationService.isAuthenticated = true;
|
AuthenticationService.isAuthenticated = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="fourteen wide column">
|
<div class="fourteen wide column">
|
||||||
<div class="ui grid container">
|
<div class="ui grid container">
|
||||||
<div class="two wide column js-navigate-bookmark" ng-class="{divHover:hoverItem}" ng-mouseover="hoverItem=true" ng-mouseleave="hoverItem=false" ng-repeat="bookmark in tag.bookmarks" ng-click="jumpToUrl(bookmark.url)" title="{{ bookmark.title }}">
|
<div
|
||||||
|
class="two wide column js-navigate-bookmark"
|
||||||
|
ng-class="{divHover:hoverItem}"
|
||||||
|
ng-mouseover="hoverItem=true"
|
||||||
|
ng-mouseleave="hoverItem=false"
|
||||||
|
ng-repeat="bookmark in tag.bookmarks"
|
||||||
|
ng-click="jumpToUrl(bookmark.url, bookmark.id)"
|
||||||
|
title="{{ bookmark.title }}">
|
||||||
<img class="ui ui middle aligned tiny image" src="http://api.byi.pw/favicon/?url={{ bookmark.url }}" style="width:16px;height:16px">
|
<img class="ui ui middle aligned tiny image" src="http://api.byi.pw/favicon/?url={{ bookmark.url }}" style="width:16px;height:16px">
|
||||||
<span>{{ bookmark.title}}</span>
|
<span>{{ bookmark.title}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,10 @@
|
||||||
var api = require('express').Router();
|
var api = require('express').Router();
|
||||||
var mysql = require('mysql');
|
var mysql = require('mysql');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
// var client = mysql.createConnection({
|
|
||||||
// host: '172.24.13.5',
|
|
||||||
// user: 'root',
|
|
||||||
// password: 'root123',
|
|
||||||
// database: 'mybookmarks',
|
|
||||||
// multipleStatements: true,
|
|
||||||
// port: 3306
|
|
||||||
// });
|
|
||||||
var client = mysql.createConnection({
|
var client = mysql.createConnection({
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
user: 'lcq',
|
user: 'lcq',
|
||||||
password: '123456',
|
password: 'fendoubuxi596320',
|
||||||
database: 'mybookmarks',
|
database: 'mybookmarks',
|
||||||
multipleStatements: true,
|
multipleStatements: true,
|
||||||
port: 3306
|
port: 3306
|
||||||
|
|
@ -28,6 +20,18 @@ api.post('/logout', function(req, res) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
api.post('/clickBookmark', function(req, res) {
|
||||||
|
var params = req.body.params;
|
||||||
|
var id = params.id;
|
||||||
|
var sql = "UPDATE `bookmarks` SET `click_count`=`click_count`+1, `last_click`=now() WHERE (`id`='" + id + "')";
|
||||||
|
console.log(sql);
|
||||||
|
client.query(sql, function(error, result, fields) {
|
||||||
|
res.json({
|
||||||
|
id: id,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
api.post('/login', function(req, res) {
|
api.post('/login', function(req, res) {
|
||||||
var params = req.body.params;
|
var params = req.body.params;
|
||||||
var username = params.username;
|
var username = params.username;
|
||||||
|
|
@ -89,6 +93,7 @@ api.get('/bookmarks', function(req, res) {
|
||||||
var tag = {
|
var tag = {
|
||||||
id: result && result[0] && result[0].tag_id,
|
id: result && result[0] && result[0].tag_id,
|
||||||
name: result && result[0] && result[0].tag_name,
|
name: result && result[0] && result[0].tag_name,
|
||||||
|
click: 0,
|
||||||
bookmarks: []
|
bookmarks: []
|
||||||
};
|
};
|
||||||
result.forEach(function(bookmark) {
|
result.forEach(function(bookmark) {
|
||||||
|
|
@ -96,17 +101,23 @@ api.get('/bookmarks', function(req, res) {
|
||||||
data.push({
|
data.push({
|
||||||
id: tag.id,
|
id: tag.id,
|
||||||
name: tag.name,
|
name: tag.name,
|
||||||
|
click: tag.click,
|
||||||
bookmarks: tag.bookmarks
|
bookmarks: tag.bookmarks
|
||||||
});
|
});
|
||||||
tag.id = bookmark.tag_id;
|
tag.id = bookmark.tag_id;
|
||||||
tag.name = bookmark.tag_name;
|
tag.name = bookmark.tag_name;
|
||||||
|
tag.click = 0;
|
||||||
tag.bookmarks = [];
|
tag.bookmarks = [];
|
||||||
}
|
}
|
||||||
|
tag.click += bookmark.click_count;
|
||||||
tag.bookmarks.push(bookmark);
|
tag.bookmarks.push(bookmark);
|
||||||
});
|
});
|
||||||
if (result && result.length > 0) {
|
if (result && result.length > 0) {
|
||||||
data.push(tag);
|
data.push(tag);
|
||||||
}
|
}
|
||||||
|
data.sort(function(a, b) {
|
||||||
|
return a.click < b.click;
|
||||||
|
})
|
||||||
res.json(data);
|
res.json(data);
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue