完成书签的显示
This commit is contained in:
parent
86d5ff15ba
commit
dd8741ebd6
|
|
@ -118,10 +118,11 @@ module.exports = class extends Base {
|
|||
// 根据书签id获取书签
|
||||
async getBookmarksByTagAction() {
|
||||
let tagId = this.get("tagId");
|
||||
let showType = this.get("showType") || "createdAt";
|
||||
// tagId = -1 个人定制 从自己里面取
|
||||
// tagId = -2 全局定制 从非个人里面取
|
||||
let where = {};
|
||||
let order = 'createdAt DESC';
|
||||
let order = showType + ' DESC';
|
||||
|
||||
if (tagId == -1) {
|
||||
where = { userId: this.ctx.state.user.id };
|
||||
|
|
@ -131,14 +132,6 @@ module.exports = class extends Base {
|
|||
where = { tagId };
|
||||
}
|
||||
|
||||
if (this.get('createdAt')) {
|
||||
order = 'createdAt DESC';
|
||||
} else if (this.get('clickCount')) {
|
||||
order = 'clickCount DESC';
|
||||
} else if (this.get('lastClick')) {
|
||||
order = 'lastClick DESC';
|
||||
}
|
||||
|
||||
try {
|
||||
let data = await this.model('bookmarks').where(where).order(order).page(this.get('page'), this.get('pageSize')).countSelect();
|
||||
this.json({ code: 0, data });
|
||||
|
|
|
|||
|
|
@ -10,25 +10,23 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
})()
|
||||
|
||||
// getTags({});
|
||||
|
||||
var pageSize = 20;
|
||||
var dialog = null;
|
||||
var forbidTransition = false;
|
||||
var addBookmarkId = -1;
|
||||
$scope.hoverBookmark = null;
|
||||
$scope.order = [false, false, false];
|
||||
$scope.order[($stateParams && $stateParams.orderIndex) || 1] = true;
|
||||
$scope.showType = "createdAt";
|
||||
$scope.loadBookmarks = false;
|
||||
$scope.loadTags = false;
|
||||
$scope.tags = []; // 书签数据
|
||||
$scope.tagsIndex = []; // 书签索引
|
||||
$scope.bookmarkClicked = false;
|
||||
$scope.bookmarksByTag = [];
|
||||
$scope.bookmarks = [];
|
||||
$scope.bookmarkCount = 0;
|
||||
$scope.totalPages = 0;
|
||||
$scope.currentPage = 1;
|
||||
$scope.inputPage = '';
|
||||
$scope.currentTagId = ($stateParams && $stateParams.tagId) || '';
|
||||
$scope.currentTagId = ($stateParams && $stateParams.tagId) || (-1);
|
||||
$scope.editMode = false;
|
||||
$scope.showMode = 'item';
|
||||
$scope.newTag = '';
|
||||
|
|
@ -38,13 +36,13 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
$scope.bookmarkNormalHover = false;
|
||||
$scope.costomTag = {
|
||||
id: -1,
|
||||
cnt: 50,
|
||||
bookmarkCount: 50,
|
||||
bookmarkClicked: false,
|
||||
name: '个人定制',
|
||||
}
|
||||
$scope.costomAllUsersTag = {
|
||||
id: -1,
|
||||
cnt: 50,
|
||||
bookmarkCount: 50,
|
||||
bookmarkClicked: false,
|
||||
name: '全站定制',
|
||||
}
|
||||
|
|
@ -56,94 +54,47 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
getTags();
|
||||
});
|
||||
|
||||
$scope.changeOrder = function (index) {
|
||||
if (index < 0 || index >= $scope.order.length) {
|
||||
return;
|
||||
}
|
||||
$scope.order = $scope.order.map(() => false);
|
||||
$scope.order[index] = true;
|
||||
$scope.bookmarksByTag = [];
|
||||
$scope.getBookmarks = async function (tagId, page, showType) {
|
||||
console.log(tagId, page, showType);
|
||||
|
||||
if ($scope.order[0]) {
|
||||
$scope.bookmarkData.bookmarks.sort(clickCmp);
|
||||
$scope.bookmarkData.bookmarks.forEach((bookmark) => {
|
||||
if (bookmark.type == 1) {
|
||||
$scope.bookmarksByTag.push(bookmark);
|
||||
}
|
||||
})
|
||||
} else if ($scope.order[1]) {
|
||||
$scope.bookmarkData.bookmarks.sort((a, b) => a.created_at >= b.created_at ? -1 : 1);
|
||||
$scope.bookmarkData.bookmarks.forEach((bookmark) => {
|
||||
if (bookmark.type == 2) {
|
||||
$scope.bookmarksByTag.push(bookmark);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
$scope.bookmarkData.bookmarks.sort((a, b) => a.last_click >= b.last_click ? -1 : 1);
|
||||
$scope.bookmarkData.bookmarks.forEach((bookmark) => {
|
||||
if (bookmark.type == 3) {
|
||||
$scope.bookmarksByTag.push(bookmark);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$timeout(function () {
|
||||
timeagoInstance.cancel();
|
||||
timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
|
||||
}, 100)
|
||||
}
|
||||
|
||||
$scope.getBookmarks = async function (tagId, page) {
|
||||
console.log(tagId, page)
|
||||
$scope.bookmarkClicked = true;
|
||||
$scope.currentTagId = tagId;
|
||||
$scope.currentPage = page;
|
||||
|
||||
tagId && ($scope.currentTagId = tagId);
|
||||
page && ($scope.currentPage = page);
|
||||
showType && ($scope.showType = showType);
|
||||
|
||||
if (!forbidTransition) {
|
||||
$scope.loadBookmarks = true;
|
||||
}
|
||||
|
||||
$scope.costomTag.bookmarkClicked = false;
|
||||
$scope.costomAllUsersTag.bookmarkClicked = false;
|
||||
|
||||
pageSize = ($scope.showMode == 'item') ? 50 : 20;
|
||||
let pageSize = ($scope.showMode == 'item') ? 50 : 20;
|
||||
|
||||
$scope.tags.forEach(function (tag) {
|
||||
tag.bookmarkClicked = false;
|
||||
if (tag.id == tagId) {
|
||||
if (tag.id == $scope.currentTagId) {
|
||||
tag.bookmarkClicked = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (tagId == -1) {
|
||||
$scope.costomTag.bookmarkClicked = true;
|
||||
}
|
||||
|
||||
if (tagId == -2) {
|
||||
$scope.costomAllUsersTag.bookmarkClicked = true;
|
||||
}
|
||||
|
||||
var params = {
|
||||
tagId,
|
||||
page,
|
||||
tagId: $scope.currentTagId,
|
||||
page: $scope.currentPage,
|
||||
pageSize,
|
||||
createdAt: true
|
||||
showType: $scope.showType
|
||||
};
|
||||
if (!forbidTransition) {
|
||||
$($scope.showMode == 'item' ? '.js-tag-costomTag' : '.js-tags-table').transition('hide');
|
||||
}
|
||||
|
||||
let data = await get('getBookmarksByTag', params);
|
||||
console.log(data);
|
||||
return;
|
||||
|
||||
bookmarkService.getBookmarksByTag(params)
|
||||
.then((data) => {
|
||||
$scope.bookmarkData = data;
|
||||
$scope.changeOrder($scope.order.indexOf(true));
|
||||
$scope.bookmarkCount = $scope.bookmarkData.totalItems;
|
||||
$scope.totalPages = tagId <= -1 ? 1 : Math.ceil($scope.bookmarkCount / pageSize);
|
||||
|
||||
let reply = await get('getBookmarksByTag', params);
|
||||
$scope.bookmarks = reply.data;
|
||||
$scope.totalPages = reply.totalPages;
|
||||
$scope.inputPage = '';
|
||||
$scope.loadBookmarks = false;
|
||||
$scope.bookmarkCount = reply.count;
|
||||
|
||||
pubSubService.publish('Common.menuActive', {
|
||||
login: true,
|
||||
|
|
@ -152,6 +103,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
if (!forbidTransition) {
|
||||
dataService.transition($scope.showMode == 'item' ? '.js-tag-costomTag' : '.js-tags-table');
|
||||
}
|
||||
|
||||
$timeout(function () {
|
||||
dataService.transition('#' + addBookmarkId, {
|
||||
duration: 1000,
|
||||
|
|
@ -159,20 +111,13 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
addBookmarkId = -1;
|
||||
}, 1000);
|
||||
forbidTransition = false;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('getTags err', err);
|
||||
$scope.loadBookmarks = false;
|
||||
forbidTransition = false;
|
||||
addBookmarkId = -1;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeCurrentPage = function (currentPage) {
|
||||
currentPage = parseInt(currentPage) || 0;
|
||||
console.log(currentPage);
|
||||
if (currentPage <= $scope.totalPages && currentPage >= 1) {
|
||||
$scope.getBookmarks($scope.currentTagId, currentPage);
|
||||
$scope.getBookmarks(null, currentPage, null);
|
||||
$scope.currentPage = currentPage;
|
||||
}
|
||||
}
|
||||
|
|
@ -189,7 +134,6 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
bookmark.last_click = $filter("date")(new Date(), "yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
})
|
||||
// $scope.changeOrder($scope.order.indexOf(true));
|
||||
$timeout(function () {
|
||||
timeagoInstance.cancel();
|
||||
timeagoInstance.render(document.querySelectorAll('.need_to_be_rendered'), 'zh_CN');
|
||||
|
|
@ -225,7 +169,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
$scope.tags.forEach((t1) => {
|
||||
$scope.waitDelBookmark.tags.forEach((t2) => {
|
||||
if (t1.id == t2.id) {
|
||||
t1.cnt--;
|
||||
t1.bookmarkCount--;
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
@ -272,7 +216,7 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
|
||||
$scope.toggleShowMode = function (showMode) {
|
||||
$scope.showMode = showMode;
|
||||
$scope.getBookmarks($scope.currentTagId, 1);
|
||||
$scope.getBookmarks(null, 1, null);
|
||||
}
|
||||
|
||||
$scope.editTag = function (tag) {
|
||||
|
|
@ -501,28 +445,34 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
$scope.tags = [];
|
||||
|
||||
let tags = await get('tags', { bookmarkCount: true });
|
||||
tags.unshift({
|
||||
id: -1,
|
||||
bookmarkCount: 1,
|
||||
bookmarkClicked: false,
|
||||
name: '个人定制',
|
||||
show: 1
|
||||
})
|
||||
|
||||
let find = false;
|
||||
for (let tag of tags) {
|
||||
tag.edit = false;
|
||||
tag.oldName = tag.name;
|
||||
$scope.tags.push(tag);
|
||||
if (tag.id == $scope.currentTagId) {
|
||||
tag.bookmarkClicked = true;
|
||||
find = true; // 如果是删了分类返回来,那么要重新默认选中第一个分类
|
||||
}
|
||||
$scope.tags.push(tag);
|
||||
}
|
||||
|
||||
if (!find && $scope.currentTagId !== -1 && $scope.currentTagId !== -2) {
|
||||
if (!find) {
|
||||
$scope.currentTagId = -1;
|
||||
$scope.costomTag.bookmarkClicked = true;
|
||||
$scope.tags[0].bookmarkClicked = true;
|
||||
}
|
||||
|
||||
if ($scope.currentTagId) {
|
||||
if (!$scope.editMode) {
|
||||
await $scope.getBookmarks($scope.currentTagId, $scope.currentPage);
|
||||
}
|
||||
} else {
|
||||
toastr.info('您还没有书签分类,请点击菜单栏的添加按钮进行添加', "提示");
|
||||
await $scope.getBookmarks(null, null, null);
|
||||
}
|
||||
|
||||
$scope.loadTags = false;
|
||||
pubSubService.publish('Common.menuActive', {
|
||||
login: true,
|
||||
|
|
@ -542,18 +492,18 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
bookmark.tags = data.tags;
|
||||
bookmark.description = data.description;
|
||||
find = true;
|
||||
if ($scope.order[bookmark.type - 1]) {
|
||||
dataService.transition('#' + bookmark.id, {
|
||||
duration: 1000,
|
||||
});
|
||||
}
|
||||
// if ($scope.order[bookmark.type - 1]) {
|
||||
// dataService.transition('#' + bookmark.id, {
|
||||
// duration: 1000,
|
||||
// });
|
||||
// }
|
||||
}
|
||||
})
|
||||
if (!find) {
|
||||
if (data.tags.map((tag) => tag.id).indexOf($scope.currentTagId) >= 0) {
|
||||
if (!$scope.editMode) {
|
||||
forbidTransition = true;
|
||||
$scope.getBookmarks($scope.currentTagId, $scope.currentPage);
|
||||
$scope.getBookmarks(null, null, null);
|
||||
}
|
||||
addBookmarkId = data.id;
|
||||
}
|
||||
|
|
@ -573,16 +523,4 @@ app.controller('tagsCtr', ['$scope', '$filter', '$state', '$window', '$statePara
|
|||
setTimeout(() => {
|
||||
$('.js-tag-label .icon').popup();
|
||||
}, 3000);
|
||||
|
||||
function clickCmp(a, b) {
|
||||
var click1 = parseInt(a.click_count);
|
||||
var click2 = parseInt(b.click_count);
|
||||
if (click1 > click2) {
|
||||
return -1;
|
||||
} else if (click1 == click2) {
|
||||
return a.url > b.url ? -1 : 1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
|
@ -1,14 +1,8 @@
|
|||
<div class="ui segment js-tags">
|
||||
<div class="ui container" ng-show="!editMode" style="cursor:default">
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomTag.bookmarkClicked}" ng-click="getBookmarks(-1, 1)">
|
||||
{{ costomTag.name }} ({{ costomTag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.bookmarkCount && tag.show" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1)">
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-if="tag.bookmarkCount && tag.show" ng-repeat="tag in tags" ng-class="{green:tag.bookmarkClicked}" ng-click="getBookmarks(tag.id, 1, null)">
|
||||
{{ tag.name }} ({{ tag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label" style="margin:3px 15px 8px 0px;cursor:default;" ng-class="{green:costomAllUsersTag.bookmarkClicked}" ng-click="getBookmarks(-2, 1)">
|
||||
{{ costomAllUsersTag.name }} ({{ costomAllUsersTag.bookmarkCount || 0 }})
|
||||
</div>
|
||||
<div class="ui label js-tag-label" style="margin:3px 15px 8px 0px;cursor:default;">
|
||||
<i class="plus icon" data-content="点击添加分类" data-position="top center" ng-click="showAddTag()"></i>
|
||||
<i class="pencil alternate icon" data-content="点击进入分类编辑模式" data-position="top center" ng-click="toggleMode(true)"></i>
|
||||
|
|
@ -64,15 +58,15 @@
|
|||
<tr>
|
||||
<th class="forbid_sorted">标题</th>
|
||||
<th class="forbid_sorted">链接</th>
|
||||
<th style="width:90px;" ng-class="{descending: order[0], sorted:order[0]}" ng-click="changeOrder(0)" title="点击可对表格进行排序">点击次数</th>
|
||||
<th style="width:100px;" ng-class="{descending: order[1], sorted:order[1]}" ng-click="changeOrder(1)" title="点击可对表格进行排序">创建日期</th>
|
||||
<th style="width:100px;" ng-class="{descending: order[2], sorted:order[2]}" ng-click="changeOrder(2)" title="点击可对表格进行排序">最后点击</th>
|
||||
<th style="width:90px;" ng-class="{descending: showType == 'createdAt', sorted:showType == 'createdAt'}" ng-click="getBookmarks(null, 1, 'createdAt')" title="点击可对表格进行排序">点击次数</th>
|
||||
<th style="width:100px;" ng-class="{descending: showType == 'clickCount', sorted:showType == 'clickCount'}" ng-click="getBookmarks(null, 1, 'clickCount')" title="点击可对表格进行排序">创建日期</th>
|
||||
<th style="width:100px;" ng-class="{descending: showType == 'lastClick', sorted:showType == 'lastClick'}" ng-click="getBookmarks(null, 1, 'lastClick')" title="点击可对表格进行排序">最后点击</th>
|
||||
<th style="width:150px;" class="forbid_sorted">分类</th>
|
||||
<th style="width:88px;" class="forbid_sorted">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="bookmark in bookmarksByTag" id="{{ bookmark.id }}" ng-mouseover="setHoverBookmark(bookmark)" ng-mouseleave="setHoverBookmark(null)">
|
||||
<tr ng-repeat="bookmark in bookmarks" id="{{ bookmark.id }}" ng-mouseover="setHoverBookmark(bookmark)" ng-mouseleave="setHoverBookmark(null)">
|
||||
<td>
|
||||
<img class="ui ui middle aligned tiny image" ng-src="http://favicon.luchenqun.com/?url={{bookmark.url}}" err-src="./images/default.ico" style="width:16px;height:16px;cursor:pointer;" ng-click="jumpToUrl(bookmark.url, bookmark.id)" />
|
||||
<span ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="{{bookmark.title}}" style="cursor:pointer;">
|
||||
|
|
@ -90,7 +84,7 @@
|
|||
<span id="time{{bookmark.id}}" title="{{bookmark.last_click}}" class="need_to_be_rendered" data-timeago="{{bookmark.last_click}}"></span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1)">
|
||||
<div class="ui label" ng-repeat="tag in bookmark.tags" tag-id="{{ tag.id }}" ng-click="getBookmarks(tag.id, 1, null)">
|
||||
{{ tag.name }}
|
||||
</div>
|
||||
</td>
|
||||
|
|
@ -111,7 +105,7 @@
|
|||
</table>
|
||||
<div class="ui segment js-tag-costomTag" ng-if="bookmarkCount > 0 && showMode=='item'" style="margin-top:-15px;" ng-show="!loadBookmarks && !editMode">
|
||||
<div class="ui five column grid">
|
||||
<div ng-repeat="bookmark in bookmarksByTag" class="column js-costomTag-item" ng-class="{bookmarkNormalHover:bookmarkNormalHover, bookmark:(!bookmarkNormalHover)}" ng-mouseover="bookmarkNormalHover=true; setHoverBookmark(bookmark)" ng-mouseleave="bookmarkNormalHover=false; setHoverBookmark(null)" ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="{{ bookmark.title }}" id="{{bookmark.id}}">
|
||||
<div ng-repeat="bookmark in bookmarks" class="column js-costomTag-item" ng-class="{bookmarkNormalHover:bookmarkNormalHover, bookmark:(!bookmarkNormalHover)}" ng-mouseover="bookmarkNormalHover=true; setHoverBookmark(bookmark)" ng-mouseleave="bookmarkNormalHover=false; setHoverBookmark(null)" ng-click="jumpToUrl(bookmark.url, bookmark.id)" title="{{ bookmark.title }}" id="{{bookmark.id}}">
|
||||
<img class="ui ui middle aligned tiny image bookmarkInfo" ng-src="http://favicon.luchenqun.com/?url={{bookmark.url}}" err-src="./images/default.ico" style="width:16px;height:16px;" ng-click="detailBookmark(bookmark);$event.stopPropagation()" />
|
||||
<span>{{ bookmark.title}}</span>
|
||||
</div>
|
||||
|
|
@ -120,17 +114,17 @@
|
|||
<div class="ui grid">
|
||||
<div class="five wide column" style="margin-top:10px;">
|
||||
<div class="ui three column grid" style="cursor: default;">
|
||||
<div class="column" ng-click="changeOrder(1)">
|
||||
<i class="add to calendar large icon" ng-class="{green: order[1]}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: order[1]}" style="margin-left:-5px;">添加日期</span>
|
||||
<div class="column" ng-click="getBookmarks(null, 1, 'createdAt')">
|
||||
<i class="add to calendar large icon" ng-class="{green: showType == 'createdAt'}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: showType == 'createdAt'}" style="margin-left:-5px;">添加日期</span>
|
||||
</div>
|
||||
<div class="column" ng-click="changeOrder(0)">
|
||||
<i class="sort numeric descending large icon" ng-class="{green: order[0]}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: order[0]}" style="margin-left:-5px;">点击次数</span>
|
||||
<div class="column" ng-click="getBookmarks(null, 1, 'clickCount')">
|
||||
<i class="sort numeric descending large icon" ng-class="{green: showType == 'clickCount'}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: showType == 'clickCount'}" style="margin-left:-5px;">点击次数</span>
|
||||
</div>
|
||||
<div class="column" ng-click="changeOrder(2)">
|
||||
<i class="sort alphabet descending large icon" ng-class="{green: order[2]}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: order[2]}" style="margin-left:-5px;">最后点击</span>
|
||||
<div class="column" ng-click="getBookmarks(null, 1, 'lastClick')">
|
||||
<i class="sort alphabet descending large icon" ng-class="{green: showType == 'lastClick'}" style="margin-bottom:4px;"></i>
|
||||
<span ng-class="{fontgreen: showType == 'lastClick'}" style="margin-left:-5px;">最后点击</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue