diff options
-rw-r--r-- | apps/files/js/filelist.js | 10 | ||||
-rw-r--r-- | apps/files_sharing/appinfo/app.php | 20 | ||||
-rw-r--r-- | apps/files_sharing/css/sharedfilelist.css | 3 | ||||
-rw-r--r-- | apps/files_sharing/js/app.js | 61 | ||||
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 190 | ||||
-rw-r--r-- | apps/files_sharing/list.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/templates/list.php | 43 | ||||
-rw-r--r-- | core/js/js.js | 11 |
8 files changed, 344 insertions, 5 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 72e1a688041..7887bdcda55 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -515,6 +515,7 @@ type = fileData.type || 'file', mtime = parseInt(fileData.mtime, 10) || new Date().getTime(), mime = fileData.mimetype, + path = fileData.path || this.getCurrentDirectory(), linkUrl; options = options || {}; @@ -550,10 +551,10 @@ // linkUrl if (type === 'dir') { - linkUrl = this.linkTo(this.getCurrentDirectory() + '/' + name); + linkUrl = this.linkTo(path + '/' + name); } else { - linkUrl = this.getDownloadUrl(name, this.getCurrentDirectory()); + linkUrl = this.getDownloadUrl(name, path); } td.append('<input id="select-' + this.id + '-' + fileData.id + '" type="checkbox" /><label for="select-' + this.id + '-' + fileData.id + '"></label>'); @@ -693,6 +694,7 @@ options = options || {}; var type = fileData.type || 'file', mime = fileData.mimetype, + path = fileData.path || this.getCurrentDirectory(), permissions = parseInt(fileData.permissions, 10) || 0; if (fileData.isShareMountPoint) { @@ -729,7 +731,7 @@ // lazy load / newly inserted td ? if (!fileData.icon) { this.lazyLoadPreview({ - path: this.getCurrentDirectory() + '/' + fileData.name, + path: path + '/' + fileData.name, mime: mime, etag: fileData.etag, callback: function(url) { @@ -740,7 +742,7 @@ else { // set the preview URL directly var urlSpec = { - file: this.getCurrentDirectory() + '/' + fileData.name, + file: path + '/' + fileData.name, c: fileData.etag }; var previewUrl = this.generatePreviewUrl(urlSpec); diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index fa43f33721c..1756fc2f50e 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -1,4 +1,5 @@ <?php +$l = OC_L10N::get('files_sharing'); OC::$CLASSPATH['OC_Share_Backend_File'] = 'files_sharing/lib/share/file.php'; OC::$CLASSPATH['OC_Share_Backend_Folder'] = 'files_sharing/lib/share/folder.php'; @@ -21,3 +22,22 @@ OCP\Util::addScript('files_sharing', 'share'); \OC_Hook::connect('OC_Appconfig', 'post_set_value', '\OCA\Files\Share\Maintainer', 'configChangeHook'); OC_FileProxy::register(new OCA\Files\Share\Proxy()); + +\OCA\Files\App::getNavigationManager()->add( + array( + "id" => 'sharingin', + "appname" => 'files_sharing', + "script" => 'list.php', + "order" => 3, + "name" => $l->t('Shared with you') + ) +); +\OCA\Files\App::getNavigationManager()->add( + array( + "id" => 'sharingout', + "appname" => 'files_sharing', + "script" => 'list.php', + "order" => 4, + "name" => $l->t('Shared with others') + ) +); diff --git a/apps/files_sharing/css/sharedfilelist.css b/apps/files_sharing/css/sharedfilelist.css new file mode 100644 index 00000000000..6b0c7d2226e --- /dev/null +++ b/apps/files_sharing/css/sharedfilelist.css @@ -0,0 +1,3 @@ +#filestable.shareList .summary .filesize { + display: none; +} diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js new file mode 100644 index 00000000000..887575193d0 --- /dev/null +++ b/apps/files_sharing/js/app.js @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +OCA.Sharing = {}; +OCA.Sharing.App = { + + _inFileList: null, + _outFileList: null, + + initSharingIn: function($el) { + if (this._inFileList) { + return; + } + + this._inFileList = new OCA.Sharing.FileList( + $el, + { + scrollContainer: $('#app-content'), + sharedWithUser: true + } + ); + + var fileActions = _.extend({}, OCA.Files.FileActions); + fileActions.registerDefaultActions(this._inFileList); + this._inFileList.setFileActions(fileActions); + }, + + initSharingOut: function($el) { + if (this._outFileList) { + return; + } + this._outFileList = new OCA.Sharing.FileList( + $el, + { + scrollContainer: $('#app-content'), + sharedWithUser: false + } + ); + + var fileActions = _.extend({}, OCA.Files.FileActions); + fileActions.registerDefaultActions(this._outFileList); + this._outFileList.setFileActions(fileActions); + } +}; + +$(document).ready(function() { + $('#app-content-sharingin').one('show', function(e) { + OCA.Sharing.App.initSharingIn($(e.target)); + }); + $('#app-content-sharingout').one('show', function(e) { + OCA.Sharing.App.initSharingOut($(e.target)); + }); +}); + diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js new file mode 100644 index 00000000000..7db4f629501 --- /dev/null +++ b/apps/files_sharing/js/sharedfilelist.js @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ +(function() { + + /** + * Sharing file list + * + * Contains both "shared with others" and "shared with you" modes. + */ + var FileList = function($el, options) { + this.initialize($el, options); + }; + + FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, { + appName: 'Shares', + + SHARE_TYPE_TEXT: [ + t('files_sharing', 'User'), + t('files_sharing', 'Group'), + t('files_sharing', 'Unknown'), + t('files_sharing', 'Public') + ], + + /** + * Whether the list shows the files shared with the user (true) or + * the files that the user shared with others (false). + */ + _sharedWithUser: false, + + initialize: function($el, options) { + OCA.Files.FileList.prototype.initialize.apply(this, arguments); + if (this.initialized) { + return; + } + + if (options && options.sharedWithUser) { + this._sharedWithUser = true; + } + }, + + /** + * Compare two shares + * @param share1 first share + * @param share2 second share + * @return 1 if share2 should come before share1, -1 + * if share1 should come before share2, 0 if they + * are identical. + */ + _shareCompare: function(share1, share2) { + var result = OCA.Files.FileList.Comparators.name(share1, share2); + if (result === 0) { + return share2.shareType - share1.shareType; + } + return result; + }, + + _createRow: function(fileData) { + // TODO: hook earlier and render the whole row here + var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments); + $tr.find('.filesize').remove(); + var $sharedWith = $('<td class="sharedWith"></td>').text(fileData.shareWithDisplayName); + var $shareType = $('<td class="shareType"></td>').text(this.SHARE_TYPE_TEXT[fileData.shareType] || + t('files_sharing', 'Unkown')); + $tr.find('td.date').before($sharedWith).before($shareType); + $tr.find('td.filename input:checkbox').remove(); + $tr.attr('data-path', fileData.path); + return $tr; + }, + + /** + * Set whether the list should contain outgoing shares + * or incoming shares. + * + * @param state true for incoming shares, false otherwise + */ + setSharedWithUser: function(state) { + this._sharedWithUser = !!state; + }, + + reload: function() { + var self = this; + this.showMask(); + if (this._reloadCall) { + this._reloadCall.abort(); + } + this._reloadCall = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', + /* jshint camelcase: false */ + data: { + format: 'json', + shared_with_me: !!this._sharedWithUser + }, + type: 'GET', + beforeSend: function(xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + error: function(result) { + self.reloadCallback(result); + }, + success: function(result) { + self.reloadCallback(result); + } + }); + }, + + reloadCallback: function(result) { + delete this._reloadCall; + this.hideMask(); + + this.$el.find('#headerSharedWith').text( + t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with') + ); + if (result.ocs && result.ocs.data) { + this.setFiles(this._makeFilesFromShares(result.ocs.data)); + } + else { + // TODO: error handling + } + }, + + render: function() { + // FIXME + /* + var $el = $('<thead><tr>' + + '<th>' + t('files', 'Name') + '</th>' + + '<th>' + t('files', 'Shared with') + '</th>' + + '<th>' + t('files', 'Type') + '</th>' + + '<th>' + t('files', 'Shared since') + '</th>' + + '</tr></thead>' + + '<tbody class="fileList"></tbody>' + + '<tfoot></tfoot>'); + this.$el.empty().append($el); + this.$fileList = this.$el.find('tbody'); + */ + }, + + /** + * Converts the OCS API share response data to a file info + * list + * @param OCS API share array + * @return array of file info maps + */ + _makeFilesFromShares: function(data) { + var self = this; + // OCS API uses non-camelcased names + /* jshint camelcase: false */ + var files = _.map(data, function(share) { + var file = { + id: share.id, + mtime: share.stime * 1000, + permissions: share.permissions + }; + if (share.item_type === 'folder') { + file.type = 'dir'; + } + else { + file.type = 'file'; + // force preview retrieval as we don't have mime types, + // the preview endpoint will fall back to the mime type + // icon if no preview exists + file.isPreviewAvailable = true; + file.icon = true; + } + file.shareType = share.share_type; + file.shareWith = share.share_with; + if (self._sharedWithUser) { + file.shareWithDisplayName = share.displayname_owner; + file.name = OC.basename(share.file_target); + file.path = OC.dirname(share.file_target); + } + else { + file.shareWithDisplayName = share.share_with_displayname; + file.name = OC.basename(share.path); + file.path = OC.dirname(share.path); + } + return file; + }); + return files.sort(this._shareCompare); + } + }); + + OCA.Sharing.FileList = FileList; +})(); diff --git a/apps/files_sharing/list.php b/apps/files_sharing/list.php new file mode 100644 index 00000000000..bad690ea95f --- /dev/null +++ b/apps/files_sharing/list.php @@ -0,0 +1,11 @@ +<?php + +// Check if we are a user +OCP\User::checkLoggedIn(); + +$tmpl = new OCP\Template('files_sharing', 'list', ''); + +OCP\Util::addScript('files_sharing', 'app'); +OCP\Util::addScript('files_sharing', 'sharedfilelist'); + +$tmpl->printPage(); diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php new file mode 100644 index 00000000000..276dc9da775 --- /dev/null +++ b/apps/files_sharing/templates/list.php @@ -0,0 +1,43 @@ +<?php /** @var $l OC_L10N */ ?> +<div id="controls"> + <div id="file_action_panel"></div> +</div> +<div id='notification'></div> + +<div id="emptycontent" class="hidden"><?php p($l->t('Nothing in here.'))?></div> + +<input type="hidden" name="dir" value="" id="dir"> + +<table id="filestable"> + <thead> + <tr> + <th id='headerName' class="hidden column-name"> + <div id="headerName-container"> + <input type="checkbox" id="select_all_trash" class="select-all"/> + <label for="select_all_trash"></label> + <a class="name sort columntitle" data-sort="name"><span><?php p($l->t( 'Name' )); ?></span><span class="sort-indicator"></span></a> + <span id="selectedActionsList" class='selectedActions'> + <a href="" class="undelete"> + <img class="svg" alt="<?php p($l->t( 'Restore' )); ?>" + src="<?php print_unescaped(OCP\image_path("core", "actions/history.svg")); ?>" /> + <?php p($l->t('Restore'))?> + </a> + </span> + </div> + </th> + <th id="headerSharedWith" class="hidden column-mtime"> + <a id="sharedwith" class="columntitle" data-sort="shareWith"><span><?php p($l->t( 'Shared with' )); ?></span><span class="sort-indicator"></span></a> + </th> + <th id="headerSharedWith" class="hidden column-mtime"> + <a id="shareType" class="columntitle" data-sort="shareType"><span><?php p($l->t( 'Type' )); ?></span><span class="sort-indicator"></span></a> + </th> + <th id="headerDate" class="hidden column-mtime"> + <a id="modified" class="columntitle" data-sort="mtime"><span><?php p($l->t( 'Shared since' )); ?></span><span class="sort-indicator"></span></a> + </th> + </tr> + </thead> + <tbody id="fileList"> + </tbody> + <tfoot> + </tfoot> +</table> diff --git a/core/js/js.js b/core/js/js.js index 3c3efc469bf..44b0a1a39af 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -211,7 +211,16 @@ var OC={ linkToRemote:function(service) { return window.location.protocol + '//' + window.location.host + OC.linkToRemoteBase(service); }, - + + /** + * Gets the base path for the given OCS API service. + * @param {string} service name + * @return {string} OCS API base path + */ + linkToOCS: function(service) { + return window.location.protocol + '//' + window.location.host + OC.webroot + '/ocs/v1.php/' + service + '/'; + }, + /** * Generates the absolute url for the given relative url, which can contain parameters. * @param {string} url |