1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-24 21:07:17 +00:00

new activity page

This commit is contained in:
lian
2015-07-24 11:37:57 +08:00
parent fa177dd150
commit dfc7f1856f
13 changed files with 340 additions and 8 deletions

View File

@@ -0,0 +1,17 @@
define([
'underscore',
'backbone',
'common',
'app/models/activity'
], function(_, Backbone, Common, Activity) {
'use strict';
var ActivityCollection = Backbone.Collection.extend({
model: Activity,
url: function () {
return Common.getUrl({name: 'events'});
}
});
return ActivityCollection;
});

View File

@@ -0,0 +1,10 @@
define([
'underscore',
'backbone'
], function(_, Backbone) {
'use strict';
var Activity = Backbone.Model.extend({});
return Activity;
});

View File

@@ -27,6 +27,7 @@ define([
'org/lib/:repo_id(/*path)': 'showOrgRepoDir',
'common/lib/:repo_id(/*path)': 'showCommonDir',
'starred/': 'showStarredFile',
'activities/': 'showEvent',
// Default
'*actions': 'showRepos'
},
@@ -90,6 +91,11 @@ define([
this.myHomeView.showStarredFile();
},
showEvent: function() {
this.switchCurrentView(this.myHomeView);
this.myHomeView.showActivity();
},
showMyRepoDir: function(repo_id, path) {
if (path) {
path = '/' + path;

View File

@@ -0,0 +1,40 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/views/details'
], function($, _, Backbone, Common, DetailesView) {
'use strict';
var ActivityItem = Backbone.View.extend({
tagName: 'li',
className: 'event-item',
template: _.template($('#activity-item-tmpl').html()),
events: {
'click .lsch': 'showDetails'
},
initialize: function(activity) {
this.activity = activity;
},
showDetails: function () {
var options = {
'repo_id': this.activity.repo_id,
'cmmt_id': this.activity.commit_id
};
new DetailesView(options);
},
render: function () {
this.$el.html(this.template({'activity': this.activity}));
return this;
}
});
return ActivityItem;
});

View File

@@ -0,0 +1,99 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/activities',
'app/views/activity-item'
], function($, _, Backbone, Common, ActivityCollection, ActivityItemView) {
'use strict';
var EventView = Backbone.View.extend({
el: $('#events'),
template: _.template($('#activities-date-tmpl').html()),
events: {
'click #events-more': 'getMoreActivites'
},
initialize: function () {
this.activities = new ActivityCollection();
this.$eventsBody = this.$('#events-body');
this.$eventsMore = this.$('#events-more');
this.$loadingTip = this.$('.loading-tip');
this.moreOffset = 0;
},
getMoreActivites: function () {
var _this = this;
this.$loadingTip.show();
this.activities.fetch({
remove: false,
data: {'start': _this.moreOffset},
success: function() {
_this.render();
}
});
},
render: function () {
var activitiesJson = this.activities.toJSON(),
len = activitiesJson.length,
more = activitiesJson[len-1]['more'],
allActivities = [];
this.$loadingTip.hide();
this.$eventsMore.hide();
this.moreOffset = activitiesJson[len-1]['more_offset'];
this.$eventsBody.empty().show();
for (var i = 0; i < len; i++) {
allActivities = allActivities.concat(activitiesJson[i]['events']);
}
var groupedActivities = _.groupBy(allActivities, 'date');
for (var date in groupedActivities) {
var $activitiesDate = $(this.template({'date': date})),
activityList = groupedActivities[date];
this.$eventsBody.append($activitiesDate);
_.each(activityList, function (activity) {
var view = new ActivityItemView(activity);
$activitiesDate.children('ol').append(view.render().el);
});
}
if (more) {
this.$eventsMore.show();
}
},
hide: function () {
this.$el.hide();
},
show: function () {
this.$el.show();
this.$loadingTip.show();
var _this = this;
this.activities.fetch({
data: {'start': 0},
success: function() {
_this.render();
}
});
}
});
return EventView;
});

View File

@@ -0,0 +1,27 @@
define([
'jquery',
'underscore',
'backbone',
'common'
], function($, _, Backbone, Common) {
'use strict';
var DetailsItemView = Backbone.View.extend({
template: _.template($('#details-item-tmpl').html()),
initialize: function(options) {
this.details_title = options.details_title;
this.details = options.details;
},
render: function () {
var data = {'details_title': this.details_title, 'details': this.details}
this.$el.html(this.template(data));
return this;
}
});
return DetailsItemView;
});

View File

@@ -0,0 +1,62 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/views/details-item'
], function($, _, Backbone, Common, DetailsItemView) {
'use strict';
var DetailsView = Backbone.View.extend({
id: 'ls-ch',
template: _.template($('#details-popup-tmpl').html()),
initialize: function (options) {
this.repo_id = options['repo_id'];
this.cmmt_id = options['cmmt_id'];
this.$el.html(this.template()).modal({autoResize:true});
$('#simplemodal-container').css({'width':'auto', 'height':'auto'});
this.getDetails();
},
getDetails: function () {
var repo_id = this.repo_id,
cmmt_id = this.cmmt_id,
details_title,
_this = this;
Common.ajaxGet({
get_url: Common.getUrl({ name:'get_history_changes', repo_id: repo_id}),
data: {'commit_id': cmmt_id},
after_op_success: function (data) {
_this.$('.loading-tip').hide();
_this.$('.commit-time').html(data['date_time']);
for (var item in data) {
if (data[item].length > 0 && item != 'date_time') {
if (item == "new") { details_title = gettext("New files") }
if (item == "removed") { details_title = gettext("Deleted files") }
if (item == "renamed") { details_title = gettext("Renamed or Moved files") }
if (item == "modified") { details_title = gettext("Modified files") }
if (item == "newdir") { details_title = gettext("New directories") }
if (item == "deldir") { details_title = gettext("Deleted directories") }
var view = new DetailsItemView({details_title: details_title, details: data[item]});
_this.$el.append(view.render().el);
}
}
$(window).resize();
},
after_op_error: function(xhr) {
Common.ajaxErrorHandler(xhr);
}
});
}
});
return DetailsView;
})

View File

@@ -7,9 +7,10 @@ define([
'app/views/myhome-sub-repos',
'app/views/myhome-shared-repos',
'app/views/starred-file',
'app/views/activity',
'app/views/myhome-side-nav'
], function($, _, Backbone, Common, ReposView, SubReposView,
SharedReposView, StarredFileView, MyhomeSideNavView) {
SharedReposView, StarredFileView, ActivityView, MyhomeSideNavView) {
'use strict';
var MyHomeView = Backbone.View.extend({
@@ -17,11 +18,11 @@ define([
initialize: function(options) {
this.sideNavView = new MyhomeSideNavView();
this.reposView = new ReposView();
this.subReposView = new SubReposView();
this.sharedReposView = new SharedReposView();
this.starredFileView = new StarredFileView();
this.activityView = new ActivityView();
this.dirView = options.dirView;
@@ -58,6 +59,13 @@ define([
this.currentView = this.starredFileView;
},
showActivity: function() {
this.sideNavView.show({'cur_tab': 'activities'});
this.currentView.hide();
this.activityView.show();
this.currentView = this.activityView;
},
showDir: function(category, repo_id, path) {
this.sideNavView.show();
var path = path || '/';