Skip to content

Commit

Permalink
MDL-32867 Display a list of references pointing to the file in filema…
Browse files Browse the repository at this point in the history
…nager
  • Loading branch information
marinaglancy committed May 21, 2012
1 parent 420e7bb commit 9dbdf31
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
13 changes: 10 additions & 3 deletions files/renderer.php
Expand Up @@ -322,13 +322,18 @@ private function fm_js_template_message() {
* disabled if they are not applicable for the particular file; * disabled if they are not applicable for the particular file;
* *
* There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated', * There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
* 'fp-size', 'fp-dimensions'. They will receive additional class 'fp-unknown' if information * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
* is unavailable. If there is information available, the content of embedded element * information is unavailable. If there is information available, the content of embedded
* with class 'fp-value' will be substituted with the value; * element with class 'fp-value' will be substituted with the value;
* *
* The value of Original ('fp-original') is loaded in separate request. When it is applicable * The value of Original ('fp-original') is loaded in separate request. When it is applicable
* but not yet loaded the 'fp-original' element receives additional class 'fp-loading'; * but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
* *
* The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
* is applicable but not yet loaded the 'fp-original' element receives additional class
* 'fp-loading'. The string explaining that XX references exist will replace content of element
* 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
*
* Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip', * Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
* 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick * 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
* events (there may be several elements with class 'fp-file-cancel'); * events (there may be several elements with class 'fp-file-cancel');
Expand Down Expand Up @@ -371,6 +376,8 @@ private function fm_js_template_fileselectlayout() {
<td class="mdl-left"><select></select></td></tr> <td class="mdl-left"><select></select></td></tr>
<tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td> <tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td>
<td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"/></td></tr> <td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"/></td></tr>
<tr class="{!}fp-reflist"><td class="mdl-right"><label>'.get_string('referenceslist', 'repository').'</label>:</td>
<td class="mdl-left"><p class="{!}fp-refcount"/><span class="fp-reflistloading">'.$icon_progress.' '.$strloading.'</span><ul class="fp-value"/></td></tr>
</table> </table>
</form> </form>
<p class="{!}fp-thumbnail"></p> <p class="{!}fp-thumbnail"></p>
Expand Down
3 changes: 3 additions & 0 deletions lang/en/repository.php
Expand Up @@ -168,6 +168,8 @@
$string['popupblockeddownload'] = 'The downloading window is blocked, please allow the popup window, and try again.'; $string['popupblockeddownload'] = 'The downloading window is blocked, please allow the popup window, and try again.';
$string['preview'] = 'Preview'; $string['preview'] = 'Preview';
$string['readonlyinstance'] = 'You cannot edit/delete a read-only instance'; $string['readonlyinstance'] = 'You cannot edit/delete a read-only instance';
$string['referencesexist'] = 'There are {$a} alias/shortcut files that use this file as their source';
$string['referenceslist'] = 'Aliases/Shortcuts';
$string['refresh'] = 'Refresh'; $string['refresh'] = 'Refresh';
$string['refreshnonjsfilepicker'] = 'Please close this window and refresh non-javascript file picker'; $string['refreshnonjsfilepicker'] = 'Please close this window and refresh non-javascript file picker';
$string['removed'] = 'Repository removed'; $string['removed'] = 'Repository removed';
Expand Down Expand Up @@ -199,6 +201,7 @@
$string['upload'] = 'Upload this file'; $string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...'; $string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully'; $string['uploadsucc'] = 'The file has been uploaded successfully';
$string['undisclosedreference'] = '(Undisclosed)';
$string['uselatestfile'] = 'Use latest file'; $string['uselatestfile'] = 'Use latest file';
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context'; $string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
$string['usenonjsfilemanager'] = 'Open file manager in new window'; $string['usenonjsfilemanager'] = 'Open file manager in new window';
Expand Down
14 changes: 14 additions & 0 deletions lib/filebrowser/file_info.php
Expand Up @@ -226,6 +226,20 @@ public function get_sortorder() {
return 0; return 0;
} }


/**
* Returns the localised human-readable name of the file together with
* virtual path
*
* @return string
*/
public function get_readable_fullname() {
$fpath = array();
for ($parent = $this; $parent; $parent = $parent->get_parent()) {
array_unshift($fpath, $parent->get_visible_name());
}
return join('/', $fpath);
}

/** /**
* Create new directory, may throw exception - make sure * Create new directory, may throw exception - make sure
* params are valid. * params are valid.
Expand Down
32 changes: 30 additions & 2 deletions lib/form/filemanager.js
Expand Up @@ -831,7 +831,7 @@ M.form_filemanager.init = function(Y, options) {
}); });
selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':''); selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':'');
// display static information about a file (when known) // display static information about a file (when known)
var attrs = ['datemodified','datecreated','size','dimensions','original']; var attrs = ['datemodified','datecreated','size','dimensions','original','reflist'];
for (var i in attrs) { for (var i in attrs) {
if (selectnode.one('.fp-'+attrs[i])) { if (selectnode.one('.fp-'+attrs[i])) {
var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : ''); var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : '');
Expand All @@ -853,7 +853,7 @@ M.form_filemanager.init = function(Y, options) {
scope: this, scope: this,
params: {'filepath':node.filepath,'filename':node.fullname}, params: {'filepath':node.filepath,'filename':node.fullname},
callback: function(id, obj, args) { callback: function(id, obj, args) {
// check if we did not select another file yet // check if we did not select another file meanwhile
var scope = args.scope; var scope = args.scope;
if (scope.selectui.fileinfo && node && if (scope.selectui.fileinfo && node &&
scope.selectui.fileinfo.filepath == node.filepath && scope.selectui.fileinfo.filepath == node.filepath &&
Expand All @@ -869,6 +869,34 @@ M.form_filemanager.init = function(Y, options) {
} }
}, false); }, false);
} }
// load references list if applicable
selectnode.one('.fp-refcount').setContent(node.refcount ? M.util.get_string('referencesexist', 'repository', node.refcount) : '');
if (node.refcount && !node.reflist) {
selectnode.one('.fp-reflist').removeClass('fp-unknown').addClass('fp-loading');
this.request({
action: 'getreferences',
scope: this,
params: {'filepath':node.filepath,'filename':node.fullname},
callback: function(id, obj, args) {
// check if we did not select another file meanwhile
var scope = args.scope;
if (scope.selectui.fileinfo && node &&
scope.selectui.fileinfo.filepath == node.filepath &&
scope.selectui.fileinfo.fullname == node.fullname) {
selectnode.one('.fp-reflist').removeClass('fp-loading');
if (obj.references) {
node.reflist = '';
for (var i in obj.references) {
node.reflist += '<li>'+obj.references[i]+'</li>';
}
selectnode.one('.fp-reflist .fp-value').setContent(node.reflist);
} else {
selectnode.one('.fp-reflist .fp-value').setContent('');
}
}
}
}, false);
}
// show panel // show panel
this.selectui.show(); this.selectui.show();
}, },
Expand Down
3 changes: 2 additions & 1 deletion lib/outputrequirementslib.php
Expand Up @@ -445,7 +445,8 @@ protected function find_module($component) {
array('nofilesattached', 'repository'), array('filepicker', 'repository'), array('logout', 'repository'), array('nofilesattached', 'repository'), array('filepicker', 'repository'), array('logout', 'repository'),
array('nofilesavailable', 'repository'), array('norepositoriesavailable', 'repository'), array('nofilesavailable', 'repository'), array('norepositoriesavailable', 'repository'),
array('fileexistsdialogheader', 'repository'), array('fileexistsdialog_editor', 'repository'), array('fileexistsdialogheader', 'repository'), array('fileexistsdialog_editor', 'repository'),
array('fileexistsdialog_filemanager', 'repository'), array('renameto', 'repository') array('fileexistsdialog_filemanager', 'repository'), array('renameto', 'repository'),
array('referencesexist', 'repository')
)); ));
break; break;
case 'core_comment': case 'core_comment':
Expand Down
28 changes: 28 additions & 0 deletions repository/draftfiles_ajax.php
Expand Up @@ -395,6 +395,34 @@
} }
die; die;


case 'getreferences':
$filename = required_param('filename', PARAM_FILE);
$filepath = required_param('filepath', PARAM_PATH);

$fs = get_file_storage();
$file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, $filename);
if (!$file) {
echo json_encode(false);
} else {
$source = unserialize($file->get_source());
$return = array('filename' => $filename, 'filepath' => $filepath, 'references' => array());
$browser = get_file_browser();
if (isset($source->original)) {
$reffiles = $fs->search_references($source->original);
foreach ($reffiles as $reffile) {
$refcontext = get_context_instance_by_id($reffile->get_contextid());
$fileinfo = $browser->get_file_info($refcontext, $reffile->get_component(), $reffile->get_filearea(), $reffile->get_itemid(), $reffile->get_filepath(), $reffile->get_filename());
if (empty($fileinfo)) {
$return['references'][] = get_string('undisclosedreference', 'repository');
} else {
$return['references'][] = $fileinfo->get_readable_fullname();
}
}
}
echo json_encode((object)$return);
}
die;

default: default:
// no/unknown action? // no/unknown action?
echo json_encode(false); echo json_encode(false);
Expand Down
5 changes: 5 additions & 0 deletions theme/base/style/filemanager.css
Expand Up @@ -291,6 +291,11 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
.filemanager.fp-select .fp-original .fp-originloading {display:none;} .filemanager.fp-select .fp-original .fp-originloading {display:none;}
.filemanager.fp-select .fp-original.fp-loading .fp-originloading {display:inline;} .filemanager.fp-select .fp-original.fp-loading .fp-originloading {display:inline;}


.filemanager.fp-select .fp-reflist.fp-unknown {display:none;}
.filemanager.fp-select .fp-reflist .fp-reflistloading {display:none;}
.filemanager.fp-select .fp-reflist.fp-loading .fp-reflistloading {display:inline;}
.filemanager.fp-select .fp-reflist .fp-value {max-width:400px;max-height:50px;overflow:auto;}

/* /*
* Create folder dialogue (File Manager only) * Create folder dialogue (File Manager only)
*/ */
Expand Down

0 comments on commit 9dbdf31

Please sign in to comment.