1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

Enable create group repo

This commit is contained in:
zhengxie
2015-01-27 17:32:31 +08:00
committed by Daniel Pan
parent 5aab457e95
commit 7920f11b41
8 changed files with 121 additions and 100 deletions

View File

@@ -7,7 +7,15 @@ define([
var GroupRepoCollection = Backbone.Collection.extend({ var GroupRepoCollection = Backbone.Collection.extend({
model: GroupRepo, model: GroupRepo,
url: app.pageOptions.groupReposUrl url: app.pageOptions.groupReposUrl,
comparator: -'mtime',
// initialize: function( ) {
// },
}); });
return new GroupRepoCollection(); return new GroupRepoCollection();

View File

@@ -7,13 +7,14 @@ define([
var GroupRepo = Backbone.Model.extend({ var GroupRepo = Backbone.Model.extend({
defaults: { defaults: {
id: "", id: null,
name: "", name: "",
desc: "", desc: "",
mtime: "", mtime: 0,
encrypted: false, encrypted: false,
permission: "", permission: "r",
owner: gettext("Unknown") owner: "-",
owner_nickname: "-"
} }
}); });

View File

@@ -17,7 +17,7 @@ define([
showDirents: function(id, path){ showDirents: function(id, path){
console.log("Repo route has been called.." + "id:" + id + " path:" + path); console.log("Repo route has been called.." + "id:" + id + " path:" + path);
new GroupView().showDirentList(id, path); // new GroupView().showDirentList(id, path);
}, },
defaultAction: function(actions){ defaultAction: function(actions){

View File

@@ -36,8 +36,14 @@ define([
// Generate the attributes for a new GroupRepo item. // Generate the attributes for a new GroupRepo item.
newAttributes: function() { newAttributes: function() {
return { return {
name: 'foo', name: $('input[name=repo_name]', this.$el).val().trim(),
desc: 'bar' desc: $('textarea[name=repo_desc]', this.$el).val().trim(),
permission: $('select[name=permission]', this.$el).val(),
// TODO: encrypted repo
// encrypted: $('#encrypt-switch', this.$el).attr('checked'),
// passwd1: $('input[name=passwd]', this.$el).val(),
// passwd2: $('input[name=passwd_again]', this.$el).val()
}; };
}, },
@@ -47,8 +53,9 @@ define([
Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT); Common.feedback('Loading...', 'info', Common.INFO_TIMEOUT);
GroupRepos.create(this.newAttributes(), { GroupRepos.create(this.newAttributes(), {
wait: true, wait: true,
prepend: true, // show newly created repo at first line
success: function() { success: function() {
Common.feedback('Success', 'success', Common.SUCCESS_TIMEOUT);
}, },
error: function() { error: function() {
Common.feedback('Error', 'error', Common.ERROR_TIMEOUT); Common.feedback('Error', 'error', Common.ERROR_TIMEOUT);

View File

@@ -2,72 +2,56 @@ define([
'jquery', 'jquery',
'underscore', 'underscore',
'backbone', 'backbone',
'common',
'app/collections/group-repos', 'app/collections/group-repos',
'app/collections/dirents', 'app/collections/dirents',
'app/views/group-repos', 'app/views/group-repos',
'app/views/add-group-repo', 'app/views/add-group-repo'
'app/views/dirents' // 'app/views/dirents'
], function($, _, Backbone, Repos, DirentCollection, GroupRepoView, AddGroupRepoView, DirentView) { ], function($, _, Backbone, Common, Repos, DirentCollection, GroupRepoView, AddGroupRepoView/*, DirentView*/) {
'use strict'; 'use strict';
var GroupView = Backbone.View.extend({ var GroupView = Backbone.View.extend({
el: '#main', el: '#main',
prepareCsrf: function() { // TODO: move to common
/* alias away the sync method */
Backbone._sync = Backbone.sync;
/* define a new sync method */
Backbone.sync = function(method, model, options) {
/* only need a token for non-get requests */
if (method == 'create' || method == 'update' || method == 'delete') {
// CSRF token value is in an embedded meta tag
// var csrfToken = $("meta[name='csrf_token']").attr('content');
var csrfToken = app.pageOptions.csrfToken;
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', csrfToken);
};
}
/* proxy the call to the old sync method */
return Backbone._sync(method, model, options);
};
},
events: { events: {
'click #repo-create': 'createRepo', 'click #repo-create': 'createRepo',
}, },
initialize: function() { initialize: function() {
this.prepareCsrf(); Common.prepareApiCsrf();
this.$cont = this.$('#right-panel'); this.$cont = this.$('#right-panel');
this.$tab = this.$('#tabs div:first-child'); this.$tab = this.$('#tabs div:first-child');
this.$tabCont = this.$('#grp-repos'); this.$tabCont = this.$('#grp-repos');
this.$tableCont = this.$('#grp-repos table');
this.$table = this.$('#grp-repos table');
this.$tableHead = $('thead', this.$table);
this.$tableBody = $('tbody', this.$table);
this.$createForm = this.$('#repo-create-form'); this.$createForm = this.$('#repo-create-form');
}, },
initializeRepos: function() { initializeRepos: function() {
this.listenTo(Repos, 'add', this.addOne); this.listenTo(Repos, 'add', this.addOne);
this.listenTo(Repos, 'reset', this.addAll); this.listenTo(Repos, 'reset', this.addAll);
this.listenTo(Repos, 'sync', this.render); // this.listenTo(Repos, 'sync', this.render);
// this.listenTo(Repos, 'all', this.render); this.listenTo(Repos, 'all', this.render); // XXX: really render table when recieve any event ?
}, },
initializeDirents: function() { all: function(event) {
this.listenTo(this.dirents, 'add', this.addOneDirent); console.log('event: ' + event);
this.listenTo(this.dirents, 'reset', this.addAllDirent);
// this.listenTo(this.dirents, 'sync', this.render);
this.listenTo(this.dirents, 'all', this.renderDirent);
}, },
addOne: function(repo) { addOne: function(repo, collection, options) {
console.log('add repo: ' + repo); console.log('add repo: ' + repo.get('name'));
var view = new GroupRepoView({model: repo}); var view = new GroupRepoView({model: repo});
this.$tableCont.append(view.render().el); if (options.prepend) {
this.$tableBody.before(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
}, },
addAll: function() { addAll: function() {
@@ -76,38 +60,18 @@ define([
Repos.each(this.addOne, this); Repos.each(this.addOne, this);
}, },
addOneDirent: function(dirent) { // Reset table by empty table body.
var view = new DirentView({model: dirent});
this.$tableCont.append(view.render().el);
},
addAllDirent: function() {
this.$tableCont.empty();
this.dirents.each(this.addOneDirent, this);
},
renderDirent: function(eventName) {
console.log('render dirents with event: ' + eventName);
if (this.dirents.length) {
this.$tabCont.show();
}
},
resetTable: function() { resetTable: function() {
console.log('rest table'); console.log('rest table');
_.each($('#grp-repos table').find('tr'), function(el, idx) { this.$tableBody.empty();
if (idx != 0) {
$(el).remove(); // remove table content except first row.
}
});
}, },
hideTable: function() { hideTable: function() {
this.$tableCont.hide(); this.$table.hide();
}, },
showTable: function() { showTable: function() {
this.$tableCont.show(); this.$table.show();
}, },
hideLoading: function() { hideLoading: function() {
@@ -126,13 +90,16 @@ define([
this.$cont.find('.empty-tips').show(); this.$cont.find('.empty-tips').show();
}, },
render: function(eventName) { render: function(event) {
console.log('got event: ' + event + ', render repo list...' );
this.hideLoading(); this.hideLoading();
if (Repos.length) { if (Repos.length) {
this.hideEmptyTips(); this.hideEmptyTips();
this.showTable(); this.showTable();
} else { } else {
this.showEmptyTips(); this.showEmptyTips();
this.hideTable();
} }
}, },
@@ -141,22 +108,8 @@ define([
Repos.fetch({reset: true}); Repos.fetch({reset: true});
}, },
showDirentList: function(id, path) {
console.log('show repo page and hide repo list: ' + id + ' ' + path);
var path = path || '/';
this.dirents = new DirentCollection(id, path);
this.initializeDirents();
this.dirents.fetch({reset: true});
// this.dirent_list = new app.DirentListView({id: id, path: path});
// $('#my-own-repos table').children().remove();
// $('#my-own-repos table').append(this.dirent_list.render().el);
},
createRepo: function() { createRepo: function() {
var view = new AddGroupRepoView(); new AddGroupRepoView();
} }
}); });

View File

@@ -130,6 +130,29 @@ define([
} }
}, },
prepareApiCsrf: function() {
/* alias away the sync method */
Backbone._sync = Backbone.sync;
/* define a new sync method */
Backbone.sync = function(method, model, options) {
/* only need a token for non-get requests */
if (method == 'create' || method == 'update' || method == 'delete') {
// CSRF token value is in an embedded meta tag
// var csrfToken = $("meta[name='csrf_token']").attr('content');
var csrfToken = app.pageOptions.csrfToken;
options.beforeSend = function(xhr){
xhr.setRequestHeader('X-CSRFToken', csrfToken);
};
}
/* proxy the call to the old sync method */
return Backbone._sync(method, model, options);
};
},
prepareCSRFToken: function(xhr, settings) { prepareCSRFToken: function(xhr, settings) {
function getCookie(name) { function getCookie(name) {
var cookieValue = null; var cookieValue = null;

View File

@@ -64,7 +64,7 @@ from seahub.utils import gen_file_get_url, gen_token, gen_file_upload_url, \
get_user_events, EMPTY_SHA1, get_ccnet_server_addr_port, \ get_user_events, EMPTY_SHA1, get_ccnet_server_addr_port, \
gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \ gen_block_get_url, get_file_type_and_ext, HAS_FILE_SEARCH, \
gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \ gen_file_share_link, gen_dir_share_link, is_org_context, gen_shared_link, \
get_org_user_events get_org_user_events, calculate_repos_last_modify
from seahub.utils.star import star_file, unstar_file from seahub.utils.star import star_file, unstar_file
from seahub.utils.file_types import IMAGE, DOCUMENT from seahub.utils.file_types import IMAGE, DOCUMENT
from seahub.utils.timeutils import utc_to_local from seahub.utils.timeutils import utc_to_local
@@ -2863,7 +2863,33 @@ class GroupRepos(APIView):
def post(self, request, group_id, format=None): def post(self, request, group_id, format=None):
# add group repo # add group repo
assert False
# TODO: perm check
username = request.user.username
repo_name = request.DATA.get("name", None)
repo_desc = request.DATA.get("desc", 'new repo')
permission = request.DATA.get("permission", 'r')
repo_id = seafile_api.create_repo(repo_name, repo_desc,
username, None)
repo = seafile_api.get_repo(repo_id)
calculate_repos_last_modify([repo])
seafile_api.set_group_repo(repo.id, int(group_id), username, permission)
group_repo = {
"id": repo.id,
"name": repo.name,
"desc": repo.desc,
"mtime": repo.latest_modify,
"encrypted": repo.encrypted,
"permission": 'rw', # Always have read-write permission to owned repo
"owner": username,
"owner_nickname": email2nickname(username)
}
return Response(group_repo, status=200)
def get(self, request, group_id, format=None): def get(self, request, group_id, format=None):
username = request.user.username username = request.user.username

View File

@@ -73,17 +73,20 @@
{% endif %} {% endif %}
</div> </div>
<div id="grp-repos"> <div id="grp-repos">
<table style="display:none"> <p class="loading">{% trans "Loading ..." %}</p>
<tr>
<th width="4%"><!--icon--></th>
<th width="20%">{% trans "Name" %} <span id="grp-repo-list-name-down" class="icon-caret-up cspt"></span> <span id="grp-repo-list-name-up" class="icon-caret-down cspt hide"></span></th>
<th width="33%">{% trans "Description" %}</th>
<th width="16%">{% trans "Last Update" %} <span id="grp-repo-list-time-up" class="icon-caret-up cspt hide"></span> <span id="grp-repo-list-time-down" class="icon-caret-down cspt"></span></th>
<th width="14%">{% trans "Shared By" %}</th>
<th width="13%">{% trans "Operations" %}</th>
</tr>
<p class="loading">{% trans "Loading ..." %}</p> <table style="display:none">
<thead>
<tr>
<th width="4%"><!--icon--></th>
<th width="20%">{% trans "Name" %} <span id="grp-repo-list-name-down" class="icon-caret-up cspt"></span> <span id="grp-repo-list-name-up" class="icon-caret-down cspt hide"></span></th>
<th width="33%">{% trans "Description" %}</th>
<th width="16%">{% trans "Last Update" %} <span id="grp-repo-list-time-up" class="icon-caret-up cspt hide"></span> <span id="grp-repo-list-time-down" class="icon-caret-down cspt"></span></th>
<th width="14%">{% trans "Shared By" %}</th>
<th width="13%">{% trans "Operations" %}</th>
</tr>
</thead>
<tbody></tbody>
</table> </table>
<div class="empty-tips" style="margin-bottom:150px; display:none;"> <div class="empty-tips" style="margin-bottom:150px; display:none;">