mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-01 15:09:14 +00:00
add admin operation logs page
This commit is contained in:
40
static/scripts/sysadmin-app/collection/admin-logs.js
Normal file
40
static/scripts/sysadmin-app/collection/admin-logs.js
Normal file
@@ -0,0 +1,40 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone.paginator',
|
||||
'common',
|
||||
'sysadmin-app/models/admin-log'
|
||||
], function(_, BackbonePaginator, Common, AdminLogModel) {
|
||||
'use strict';
|
||||
|
||||
var AdminLogCollection = Backbone.PageableCollection.extend({
|
||||
|
||||
model: AdminLogModel,
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'admin-logs'});
|
||||
},
|
||||
|
||||
state: {
|
||||
firstPage: 1,
|
||||
pageSize: 100,
|
||||
},
|
||||
|
||||
// Setting `null` as the value of any mapping
|
||||
// will remove it from the query string.
|
||||
queryParams: {
|
||||
currentPage: "page",
|
||||
pageSize: "per_page",
|
||||
totalPages: null,
|
||||
totalRecords: null,
|
||||
},
|
||||
|
||||
parseState: function (resp) {
|
||||
return {totalRecords: resp.total_count};
|
||||
},
|
||||
|
||||
parseRecords: function (resp) {
|
||||
return resp.data;
|
||||
}
|
||||
});
|
||||
return AdminLogCollection;
|
||||
});
|
11
static/scripts/sysadmin-app/models/admin-log.js
Normal file
11
static/scripts/sysadmin-app/models/admin-log.js
Normal file
@@ -0,0 +1,11 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
], function(_, Backbone, Common) {
|
||||
'use strict';
|
||||
|
||||
var AdminLogModel = Backbone.Model.extend({});
|
||||
|
||||
return AdminLogModel;
|
||||
});
|
@@ -18,12 +18,13 @@ define([
|
||||
'sysadmin-app/views/search-groups',
|
||||
'sysadmin-app/views/group-repos',
|
||||
'sysadmin-app/views/group-members',
|
||||
'sysadmin-app/views/admin-logs',
|
||||
'app/views/account'
|
||||
], function($, Backbone, Common, SideNavView, DashboardView,
|
||||
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
|
||||
ReposView, SearchReposView, SystemReposView, TrashReposView,
|
||||
SearchTrashReposView, DirView, GroupsView, SearchGroupsView,
|
||||
GroupReposView, GroupMembersView, AccountView) {
|
||||
GroupReposView, GroupMembersView, AdminLogsView, AccountView) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -42,8 +43,10 @@ define([
|
||||
'libs/:repo_id(/*path)': 'showLibraryDir',
|
||||
'groups/': 'showGroups',
|
||||
'search-groups/': 'showSearchGroups',
|
||||
'groups/:group_id/': 'showGroupLibraries',
|
||||
'groups/:group_id/libs/': 'showGroupLibraries',
|
||||
'groups/:group_id/members/': 'showGroupMembers',
|
||||
'admin-logs/': 'showAdminLogs',
|
||||
// Default
|
||||
'*actions': 'showDashboard'
|
||||
},
|
||||
@@ -76,6 +79,8 @@ define([
|
||||
this.groupReposView = new GroupReposView();
|
||||
this.groupMembersView = new GroupMembersView();
|
||||
|
||||
this.adminLogsView = new AdminLogsView();
|
||||
|
||||
app.ui.accountView = this.accountView = new AccountView();
|
||||
|
||||
this.currentView = this.dashboardView;
|
||||
@@ -223,6 +228,20 @@ define([
|
||||
this.switchCurrentView(this.groupMembersView);
|
||||
this.sideNavView.setCurTab('groups');
|
||||
this.groupMembersView.show(group_id);
|
||||
},
|
||||
|
||||
showAdminLogs: function() {
|
||||
var url = window.location.href;
|
||||
var page = url.match(/.*?page=(\d+)/);
|
||||
if (page) {
|
||||
var current_page = page[1];
|
||||
} else {
|
||||
var current_page = null;
|
||||
}
|
||||
|
||||
this.switchCurrentView(this.adminLogsView);
|
||||
this.sideNavView.setCurTab('admin-logs');
|
||||
this.adminLogsView.show({'current_page': current_page});
|
||||
}
|
||||
|
||||
});
|
||||
|
38
static/scripts/sysadmin-app/views/admin-log.js
Normal file
38
static/scripts/sysadmin-app/views/admin-log.js
Normal file
@@ -0,0 +1,38 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'moment',
|
||||
'app/views/widgets/hl-item-view'
|
||||
], function($, _, Backbone, Common, Moment, HLItemView) {
|
||||
'use strict';
|
||||
|
||||
var AdminLogView = HLItemView.extend({
|
||||
tagName: 'tr',
|
||||
|
||||
template: _.template($('#admin-log-item-tmpl').html()),
|
||||
|
||||
events: {
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
HLItemView.prototype.initialize.call(this);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var data = this.model.toJSON(),
|
||||
created_at = Moment(data['datetime']);
|
||||
|
||||
data['time'] = created_at.format('LLLL');
|
||||
data['time_from_now'] = Common.getRelativeTimeStr(created_at);
|
||||
|
||||
this.$el.html(this.template(data));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return AdminLogView;
|
||||
});
|
159
static/scripts/sysadmin-app/views/admin-logs.js
Normal file
159
static/scripts/sysadmin-app/views/admin-logs.js
Normal file
@@ -0,0 +1,159 @@
|
||||
define([
|
||||
'jquery',
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'sysadmin-app/views/admin-log',
|
||||
'sysadmin-app/collection/admin-logs'
|
||||
], function($, _, Backbone, Common, AdminLogView, AdminLogCollection) {
|
||||
'use strict';
|
||||
|
||||
var AdminLogsView = Backbone.View.extend({
|
||||
|
||||
id: 'admin-logs',
|
||||
|
||||
template: _.template($("#admin-logs-tmpl").html()),
|
||||
|
||||
initialize: function() {
|
||||
this.adminLogCollection = new AdminLogCollection();
|
||||
this.listenTo(this.adminLogCollection, 'add', this.addOne);
|
||||
this.listenTo(this.adminLogCollection, 'reset', this.reset);
|
||||
this.render();
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.$el.append(this.template());
|
||||
|
||||
this.$table = this.$('table');
|
||||
this.$tableBody = $('tbody', this.$table);
|
||||
this.$loadingTip = this.$('.loading-tip');
|
||||
this.$emptyTip = this.$('.empty-tips');
|
||||
|
||||
this.$jsPrevious = this.$('.js-previous');
|
||||
this.$jsNext = this.$('.js-next');
|
||||
},
|
||||
|
||||
events: {
|
||||
'click #paginator .js-next': 'getNextPage',
|
||||
'click #paginator .js-previous': 'getPreviousPage'
|
||||
},
|
||||
|
||||
getNextPage: function() {
|
||||
this.initPage();
|
||||
this.adminLogCollection.getNextPage({reset: true});
|
||||
return false;
|
||||
},
|
||||
|
||||
getPreviousPage: function() {
|
||||
this.initPage();
|
||||
this.adminLogCollection.getPreviousPage({reset: true});
|
||||
return false;
|
||||
},
|
||||
|
||||
initPage: function() {
|
||||
this.$loadingTip.show();
|
||||
this.$table.hide();
|
||||
this.$tableBody.empty();
|
||||
this.$emptyTip.hide();
|
||||
|
||||
this.$jsNext.hide();
|
||||
this.$jsPrevious.hide();
|
||||
},
|
||||
|
||||
hide: function() {
|
||||
this.$el.detach();
|
||||
this.attached = false;
|
||||
},
|
||||
|
||||
show: function(option) {
|
||||
this.option = option;
|
||||
if (!this.attached) {
|
||||
this.attached = true;
|
||||
$("#right-panel").html(this.$el);
|
||||
}
|
||||
this.getContent();
|
||||
},
|
||||
|
||||
renderPaginator: function() {
|
||||
if (this.adminLogCollection.hasNextPage()) {
|
||||
this.$jsNext.show();
|
||||
} else {
|
||||
this.$jsNext.hide();
|
||||
}
|
||||
|
||||
if (this.adminLogCollection.hasPreviousPage()) {
|
||||
this.$jsPrevious.show();
|
||||
} else {
|
||||
this.$jsPrevious.hide();
|
||||
}
|
||||
},
|
||||
|
||||
getContent: function() {
|
||||
this.initPage();
|
||||
|
||||
var _this = this;
|
||||
var current_page = parseInt(this.option.current_page) || 1;
|
||||
var first_page = parseInt(this.adminLogCollection.state.firstPage);
|
||||
var total_page = parseInt(this.adminLogCollection.state.totalPages);
|
||||
|
||||
// `currentPage` must be firstPage <= currentPage < totalPages if 1-based.
|
||||
if (first_page <= current_page && current_page < total_page) {
|
||||
this.adminLogCollection.getPage(current_page).done(function () {
|
||||
_this.$loadingTip.hide();
|
||||
var current_page = _this.adminLogCollection.state.currentPage;
|
||||
app.router.navigate('admin-logs/?page=' + current_page);
|
||||
|
||||
if (_this.adminLogCollection.length > 0) {
|
||||
_this.$table.show();
|
||||
} else {
|
||||
_this.$emptyTip.show();
|
||||
}
|
||||
|
||||
_this.renderPaginator();
|
||||
});
|
||||
} else {
|
||||
// always get the first page if not use `getPage` method
|
||||
_this.adminLogCollection.state.currentPage = 1;
|
||||
this.adminLogCollection.fetch({
|
||||
cache: false,
|
||||
reset: true,
|
||||
error: function(collection, response, opts) {
|
||||
var err_msg;
|
||||
if (response.responseText) {
|
||||
if (response['status'] == 401 || response['status'] == 403) {
|
||||
err_msg = gettext("Permission error");
|
||||
} else {
|
||||
err_msg = $.parseJSON(response.responseText).error_msg;
|
||||
}
|
||||
} else {
|
||||
err_msg = gettext("Failed. Please check the network.");
|
||||
}
|
||||
Common.feedback(err_msg, 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
addOne: function(log) {
|
||||
var view = new AdminLogView({model: log});
|
||||
this.$tableBody.append(view.render().el);
|
||||
},
|
||||
|
||||
reset: function() {
|
||||
this.$loadingTip.hide();
|
||||
|
||||
var current_page = this.adminLogCollection.state.currentPage;
|
||||
app.router.navigate('admin-logs/?page=' + current_page);
|
||||
|
||||
if (this.adminLogCollection.length > 0) {
|
||||
this.adminLogCollection.each(this.addOne, this);
|
||||
this.$table.show();
|
||||
} else {
|
||||
this.$emptyTip.show();
|
||||
}
|
||||
|
||||
this.renderPaginator();
|
||||
}
|
||||
});
|
||||
return AdminLogsView;
|
||||
});
|
Reference in New Issue
Block a user