增加了点击更新点击次数,最后一次点击数,分类如果是空过滤,排序显示按照分类总点击数

This commit is contained in:
luchenqun 2016-11-03 21:05:58 +08:00
parent de8b327d4d
commit 230066b84b
5 changed files with 52 additions and 16 deletions

View File

@ -10,8 +10,11 @@ app.controller('bookmarksCtr', ['$scope', '$state', '$stateParams', '$filter', '
show: $scope.showStyle,
}
$scope.jumpToUrl = function(url) {
$scope.jumpToUrl = function(url, id) {
$window.open(url, '_blank');
bookmarkService.clickBookmark({
id: id
});
}
getBookmarks(params);
pubSubService.subscribe('MenuCtr.bookmarks', $scope, function(event, params) {

View File

@ -25,10 +25,12 @@ app.controller('editCtr', ['$scope', '$state', '$timeout', 'bookmarkService', 'p
var params = [];
tags.forEach(function(tag) {
tag = tag.replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, ' '); // 去除前后空格,多个空格转为一个空格;
// 过滤是""的情况
if (tag) {
params.push(tag);
}
});
console.log(params);
bookmarkService.addTags(params).then(
function(data) {
$scope.tags = data;

View File

@ -15,6 +15,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) {
});
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) {
var def = $q.defer();
$http.post('/api/logout/', {

View File

@ -6,7 +6,14 @@
</div>
<div class="fourteen wide column">
<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">
<span>{{ bookmark.title}}</span>
</div>

View File

@ -1,18 +1,10 @@
var api = require('express').Router();
var mysql = require('mysql');
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({
host: '127.0.0.1',
user: 'lcq',
password: '123456',
password: 'fendoubuxi596320',
database: 'mybookmarks',
multipleStatements: true,
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) {
var params = req.body.params;
var username = params.username;
@ -89,6 +93,7 @@ api.get('/bookmarks', function(req, res) {
var tag = {
id: result && result[0] && result[0].tag_id,
name: result && result[0] && result[0].tag_name,
click: 0,
bookmarks: []
};
result.forEach(function(bookmark) {
@ -96,17 +101,23 @@ api.get('/bookmarks', function(req, res) {
data.push({
id: tag.id,
name: tag.name,
click: tag.click,
bookmarks: tag.bookmarks
});
tag.id = bookmark.tag_id;
tag.name = bookmark.tag_name;
tag.click = 0;
tag.bookmarks = [];
}
tag.click += bookmark.click_count;
tag.bookmarks.push(bookmark);
});
if (result && result.length > 0) {
data.push(tag);
}
data.sort(function(a, b) {
return a.click < b.click;
})
res.json(data);
})
} else {