diff --git a/media/scripts/app/collections/repos.js b/media/scripts/app/collections/repos.js index 03203899ee..eb76241bf9 100644 --- a/media/scripts/app/collections/repos.js +++ b/media/scripts/app/collections/repos.js @@ -8,15 +8,19 @@ define([ var RepoCollection = Backbone.Collection.extend({ model: Repo, url: app.pageOptions.reposUrl, + type: 'mine', - initialize: function() { + initialize: function(options) { //console.log('init RepoCollection'); + if (options) { + this.type = options.type ? options.type : 'mine'; + } }, fetch: function(options) { // override default fetch url options = options ? _.clone(options) : {}; - options.url = this.url + '?type=mine' + options.url = this.url + '?type=' + this.type; //call Backbone's fetch return Backbone.Collection.prototype.fetch.call(this, options); diff --git a/media/scripts/app/routers/myhome.js b/media/scripts/app/routers/myhome.js index df8b65f1bb..e5acf88b1e 100644 --- a/media/scripts/app/routers/myhome.js +++ b/media/scripts/app/routers/myhome.js @@ -10,6 +10,8 @@ define([ var MyHomeRouter = Backbone.Router.extend({ routes: { 'lib/:repo_id(/*path)': 'showDir', + 'my-libs': 'showMyRepos', + 'shared-libs': 'showSharedRepos', // Default '*actions': 'defaultAction' @@ -29,11 +31,21 @@ define([ this.myHomeView.showDir(repo_id, path); }, + showMyRepos: function() { + console.log("show My Repos"); + this.myHomeView.showMyRepos(); + }, + + showSharedRepos: function() { + console.log("show shared repos"); + this.myHomeView.showSharedRepos(); + }, + defaultAction: function(actions) { // We have no matching route, lets just log what the URL was console.log('No route:', actions); - this.myHomeView.showRepoList(); + this.myHomeView.showMyRepos(); } }); diff --git a/media/scripts/app/views/myhome-repos.js b/media/scripts/app/views/myhome-repos.js index 1c1cfe2b18..1bc38f26ad 100644 --- a/media/scripts/app/views/myhome-repos.js +++ b/media/scripts/app/views/myhome-repos.js @@ -69,6 +69,7 @@ define([ hide: function() { this.$el.hide(); + this.$table.hide(); }, createRepo: function() { diff --git a/media/scripts/app/views/myhome-shared-repos.js b/media/scripts/app/views/myhome-shared-repos.js new file mode 100644 index 0000000000..5be2696f51 --- /dev/null +++ b/media/scripts/app/views/myhome-shared-repos.js @@ -0,0 +1,74 @@ +define([ + 'jquery', + 'underscore', + 'backbone', + 'common', + 'app/collections/repos', + 'app/views/shared-repo', +], function($, _, Backbone, Common, RepoCollection, SharedRepoView) { + 'use strict'; + + var SharedReposView = Backbone.View.extend({ + el: $('#repo-tabs'), + + initialize: function(options) { + this.$tabs = $('#repo-tabs'); + this.$table = this.$('#repos-shared-to-me table'); + this.$tableHead = $('thead', this.$table); + this.$tableBody = $('tbody', this.$table); + this.$loadingTip = $('.loading-tip', this.$tabs); + this.$emptyTip = $('.empty-tips', this.tabs); + + this.repos = new RepoCollection({type: 'shared'}); + this.listenTo(this.repos, 'add', this.addOne); + this.listenTo(this.repos, 'reset', this.reset); + }, + + addOne: function(repo, collection, options) { + var view = new SharedRepoView({model: repo}); + if (options.prepend) { + this.$tableBody.prepend(view.render().el); + } else { + this.$tableBody.append(view.render().el); + } + }, + + reset: function() { + this.$tableBody.empty(); + this.repos.each(this.addOne, this); + if (this.repos.length) { + this.$emptyTip.hide(); + this.$table.show(); + } else { + this.$emptyTip.show(); + this.$table.hide(); + } + this.$loadingTip.hide(); + }, + + renderPath: function() { + // + }, + + showSharedRepos: function() { + this.repos.fetch({reset: true}); + this.$tabs.show(); + //this.$table.parent().show(); + this.$table.hide(); + this.$loadingTip.show(); + }, + + show: function() { + this.showSharedRepos(); + }, + + hide: function() { + this.$el.hide(); + this.$table.hide(); + }, + + + }); + + return SharedReposView; +}); diff --git a/media/scripts/app/views/myhome.js b/media/scripts/app/views/myhome.js index 2141e55d05..96575e1fd3 100644 --- a/media/scripts/app/views/myhome.js +++ b/media/scripts/app/views/myhome.js @@ -5,10 +5,11 @@ define([ 'common', 'app/collections/groups', 'app/views/myhome-repos', + 'app/views/myhome-shared-repos', 'app/views/dir', 'app/views/group-nav', ], function($, _, Backbone, Common, GroupCollection, - ReposView, DirView, GroupNavView) { + ReposView, SharedReposView, DirView, GroupNavView) { 'use strict'; var MyHomeView = Backbone.View.extend({ @@ -24,6 +25,7 @@ define([ this.$cont = this.$('#right-panel'); this.reposView = new ReposView(); + this.sharedReposView = new SharedReposView(); this.dirView = new DirView(); this.groupView = new GroupNavView(); }, @@ -45,12 +47,19 @@ define([ this.$cont.find('.loading').show(); }, - showRepoList: function() { + showMyRepos: function() { console.log('show repo list'); + this.sharedReposView.hide(); this.reposView.show(); this.dirView.hide(); }, + showSharedRepos: function() { + this.dirView.hide(); + this.reposView.hide(); + this.sharedReposView.show(); + }, + showDir: function(repo_id, path) { console.log('show dir ' + repo_id + ' ' + path); diff --git a/media/scripts/app/views/repo.js b/media/scripts/app/views/repo.js index d41e87d2fc..2a061fd094 100644 --- a/media/scripts/app/views/repo.js +++ b/media/scripts/app/views/repo.js @@ -3,7 +3,7 @@ define([ 'underscore', 'backbone', 'common', - 'text!' + app.config._tmplRoot + 'repos.html' + 'text!' + app.config._tmplRoot + 'repo.html' ], function($, _, Backbone, Common, reposTemplate) { 'use strict'; @@ -18,7 +18,7 @@ define([ 'click .repo-delete-btn': 'delete', 'click .repo-share-btn': 'share' }, - + initialize: function() { console.log('init RepoView'); diff --git a/media/scripts/app/views/shared-repo.js b/media/scripts/app/views/shared-repo.js new file mode 100644 index 0000000000..676843f173 --- /dev/null +++ b/media/scripts/app/views/shared-repo.js @@ -0,0 +1,45 @@ +define([ + 'jquery', + 'underscore', + 'backbone', + 'common', + 'text!' + app.config._tmplRoot + 'shared-repo.html' +], function($, _, Backbone, Common, reposTemplate) { + 'use strict'; + + var SharedRepoView = Backbone.View.extend({ + tagName: 'tr', + + template: _.template(reposTemplate), + + events: { + 'mouseenter': 'showAction', + 'mouseleave': 'hideAction', + 'click .repo-delete-btn': 'delete', + 'click .repo-share-btn': 'share' + }, + + initialize: function() { + this.listenTo(this.model, 'destroy', this.remove); + }, + + render: function() { + this.$el.html(this.template(this.model.toJSON())); + return this; + }, + + showAction: function() { + this.$el.addClass('hl'); + this.$el.find('.op-icon').removeClass('vh'); + }, + + hideAction: function() { + this.$el.removeClass('hl'); + this.$el.find('.op-icon').addClass('vh'); + }, + + + }); + + return SharedRepoView; +}); diff --git a/seahub/api2/views.py b/seahub/api2/views.py index d45819e3aa..9bb18bd97d 100644 --- a/seahub/api2/views.py +++ b/seahub/api2/views.py @@ -569,6 +569,7 @@ class Repos(APIView): "name":r.repo_name, "desc":r.repo_desc, "mtime":r.latest_modify, + "mtime_relative": translate_seahub_time(r.latest_modify), "root":r.root, "size":r.size, "encrypted":r.encrypted, diff --git a/seahub/templates/js/repos.html b/seahub/templates/js/repo.html similarity index 100% rename from seahub/templates/js/repos.html rename to seahub/templates/js/repo.html diff --git a/seahub/templates/js/shared-repo.html b/seahub/templates/js/shared-repo.html new file mode 100644 index 0000000000..70519bd5da --- /dev/null +++ b/seahub/templates/js/shared-repo.html @@ -0,0 +1,18 @@ +{% load i18n %} +
{% trans "You can create a library to organize your files. For example, you can create one for each of your projects. Each library can be synchronized and shared separately." %}