#1548 '[+]' locked files

This commit is contained in:
Karel Pičman 2024-09-20 13:36:14 +02:00
parent a56fcc33a2
commit 911d03af5e
3 changed files with 64 additions and 39 deletions

View File

@ -80,7 +80,9 @@
files = [] files = []
project_or_folder.dmsf_files.visible.each do |dmsf_file| project_or_folder.dmsf_files.visible.each do |dmsf_file|
rev = dmsf_file.last_revision rev = dmsf_file.last_revision
files << [dmsf_file.name, rev.major_version, rev.minor_version, rev.patch_version ] if rev if rev
files << [dmsf_file.name, rev.major_version, rev.minor_version, rev.patch_version, dmsf_file.locked_for_user? ]
end
end end
%> %>
<%= file_field_tag 'dmsf_attachments[dummy][file]', <%= file_field_tag 'dmsf_attachments[dummy][file]',
@ -100,6 +102,9 @@
dmsf_file_details_form: controller.send(:render_to_string, dmsf_file_details_form: controller.send(:render_to_string,
{ partial: 'dmsf_upload/upload_file', { partial: 'dmsf_upload/upload_file',
locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }), locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }),
dmsf_file_details_form_locked: controller.send(:render_to_string,
{ partial: 'dmsf_upload/upload_file_locked',
locals: { upload: DmsfUpload.new(project, folder, nil), i: 0 } }),
files: JSON.generate(files) files: JSON.generate(files)
} }
%> %>

View File

@ -19,68 +19,48 @@
%> %>
<div class="box tabular dmfs-box-tabular"> <div class="box tabular dmfs-box-tabular">
<%= hidden_field_tag "committed_files[#{i}][disk_filename]", upload.disk_filename %>
<%= hidden_field_tag "committed_files[#{i}][token]", upload.token %>
<%= hidden_field_tag "committed_files[#{i}][size]", upload.size %>
<%= hidden_field_tag "committed_files[#{i}][mime_type]", upload.mime_type %>
<%= hidden_field_tag "committed_files[#{i}][name]", upload.name %>
<%= hidden_field_tag "committed_files[#{i}][digest]", upload.digest %>
<p class="warning"><%= l(:info_file_locked) %></p> <p class="warning"><%= l(:info_file_locked) %></p>
<div class="splitcontent"> <div class="splitcontent">
<div class="splitcontentleft"> <div class="splitcontentleft">
<p> <p>
<%= label_tag '', l(:label_title) %> <%= label_tag "committed_files[#{i}][title]", l(:label_title) %>
<%= text_field_tag :name, h(upload.title), readonly: true %> <%= text_field_tag "committed_files[#{i}][title]", upload.title, readonly: true %>
</p> </p>
</div> </div>
<div class="splitcontentright"> <div class="splitcontentright">
<p> <p>
<%= label_tag '', l(:label_filename) %> <%= label_tag "committed_files[#{i}][name]", l(:label_filename) %>
<%= text_field_tag :name, h(upload.name), readonly: true %> <%= text_field_tag "committed_files[#{i}][name]", upload.name, readonly: true %>
</p> </p>
</div> </div>
</div> </div>
<% if upload.description.present? %>
<p>
<%= label_tag '', l(:label_description) %>
<div class="wiki">
<%= textilizable upload.description %>
</div>
</p>
<% end %>
<div class="splitcontent"> <div class="splitcontent">
<div class="splitcontentleft"> <div class="splitcontentleft">
<p> <p>
<%= label_tag '', l(:label_dmsf_version) %> <%= label_tag "committed_files[#{i}][version]", l(:label_dmsf_version) %>
<%= text_field_tag :name, <%= text_field_tag "committed_files[#{i}][version]",
"#{DmsfUploadHelper::gui_version(upload.major_version)}.#{DmsfUploadHelper::gui_version(upload.minor_version)}", "#{DmsfUploadHelper::gui_version(upload.major_version)}.#{DmsfUploadHelper::gui_version(upload.minor_version)}",
readonly: true %> readonly: true %>
</p> </p>
<p> <p>
<%= label_tag '', l(:label_mime) %> <%= label_tag "committed_files[#{i}][mime_type]", l(:label_mime) %>
<%= text_field_tag :name, h(upload.mime_type), readonly: true %> <%= text_field_tag "committed_files[#{i}][mime_type]", upload.mime_type, readonly: true %>
</p> </p>
<p> <p>
<%= label_tag '', l(:label_size) %> <%= label_tag "committed_files[#{i}][size]", l(:label_size) %>
<%= text_field_tag :name, h(number_to_human_size(upload.size)), readonly: true %> <%= text_field_tag "committed_files[#{i}][size]", number_to_human_size(upload.size), readonly: true %>
</p> </p>
</div> </div>
<div class="splitcontentright"> <div class="splitcontentright">
<div class="custom_fields"> <div class="custom_fields">
<% upload.custom_values.each do |value| %> <% upload.custom_values.each do |value| %>
<p> <p>
<%= label_tag '', h(value.custom_field.name) %> <%= label_tag "committed_files[#{i}][#{value.custom_field.id}]", value.custom_field.name %>
<% value.value = nil if value.custom_field.dmsf_not_inheritable %> <% value.value = nil if value.custom_field.dmsf_not_inheritable %>
<%= text_field_tag :name, h(value.value), readonly: true %> <%= text_field_tag "committed_files[#{i}][#{value.custom_field.id}]", value.value, readonly: true %>
</p> </p>
<% end %> <% end %>
</div> </div>
</div> </div>
</div> </div>
<% if upload.comment.present? %>
<p>
<%= label_tag '', l(:label_comment) %>
<div class="wiki"><%= textilizable upload.comment %></div>
</p>
<% end %>
</div> </div>

View File

@ -97,6 +97,36 @@ function getNextVersion(filename, files) {
return [0, 1, null]; return [0, 1, null];
} }
/* Get the current version */
function getCurrentVersion(filename, files) {
for(let i = 0; i < files.length; i++) {
if (filename === files[i][0]) {
let res = '';
if (files[i][3] != null) {
res = '.' + files[i][3];
}
if (files[i][2] != null) {
res = '.' + files[i][2] + res;
}
if (files[i][1] != null) {
res = files[i][1] + res;
}
return res;
}
}
return '0.1.0';
}
/* Detects locked file */
function isFileLocked(filename, files) {
for(let i = 0; i < files.length; i++) {
if (filename === files[i][0]) {
return files[i][4];
}
}
return false;
}
/* Replace selected version */ /* Replace selected version */
function replaceVersion(detailsForm, attachmentId, name, version) { function replaceVersion(detailsForm, attachmentId, name, version) {
let index = detailsForm.search('id="committed_files_' + attachmentId + '_version_' + name + '"'); let index = detailsForm.search('id="committed_files_' + attachmentId + '_version_' + name + '"');
@ -149,10 +179,9 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
} }
// Details // Details
let detailsForm = $(inputEl).data('dmsf-file-details-form');
let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId}); let detailsDiv = $('<div>').attr({id: 'dmsf_attachments_details_' + attachmentId});
let detailsArrow = $('<a>'); let detailsArrow = $('<a>');
detailsArrow.text('[+]'); detailsArrow.text('[+]');
detailsArrow.attr({href: "#", 'data-cy': 'toggle__new_revision_from_content--dmsf', title: 'Details'}); detailsArrow.attr({href: "#", 'data-cy': 'toggle__new_revision_from_content--dmsf', title: 'Details'});
detailsArrow.attr( detailsArrow.attr(
@ -164,6 +193,10 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
"$('#dmsf-upload-button').hide();" + "$('#dmsf-upload-button').hide();" +
"return false;" "return false;"
}); });
let files = $(inputEl).data('files');
let locked = isFileLocked(file.name, files);
let detailsForm = $(inputEl).data(locked ? 'dmsf-file-details-form-locked' : 'dmsf-file-details-form');
// Index // Index
detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']'); detailsForm = detailsForm.replace(/\[0\]/g, '[' + attachmentId + ']');
detailsForm = detailsForm.replace(/_0/g, '_' + attachmentId); detailsForm = detailsForm.replace(/_0/g, '_' + attachmentId);
@ -180,10 +213,17 @@ function dmsfAddFile(inputEl, file, eagerUpload) {
detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_mime_type"', detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_mime_type"',
'id="committed_files_' + attachmentId + '_mime_type" value = "' + file.type + '"'); 'id="committed_files_' + attachmentId + '_mime_type" value = "' + file.type + '"');
// Version // Version
let version = getNextVersion(file.name, $(inputEl).data('files')); let version;
detailsForm = replaceVersion(detailsForm, attachmentId, 'patch', version[2]); if(locked) {
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]); version = getCurrentVersion(file.name, files);
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]); detailsForm = detailsForm.replace('id="committed_files_' + attachmentId + '_version" value="0.0"',
'id="committed_files_' + attachmentId + '_version" value="' + version + '"');
} else {
version = getNextVersion(file.name, files);
detailsForm = replaceVersion(detailsForm, attachmentId, 'patch', version[2]);
detailsForm = replaceVersion(detailsForm, attachmentId, 'minor', version[1]);
detailsForm = replaceVersion(detailsForm, attachmentId, 'major', version[0]);
}
detailsDiv.append(detailsForm); detailsDiv.append(detailsForm);
detailsDiv.hide(); detailsDiv.hide();