ruling_timer/app/views/admin/ruling_timers/view_task.html.erb

256 lines
9.2 KiB
Plaintext

<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<style type="text/css">
.markdown_text:not(.ready){
display: none;
}
</style>
<style type="text/css">
.working_label{
color: #5a5a5a;
font-weight: bold;
}
.finish_label{
color: #3ec700;
font-weight: bold;
}
.stop_label{
color: #cd1643;
font-weight: bold;
}
.details_block {
font-size: 1.3em;
}
.main_fields{
font-size: 1.3em;
}
.custom_hr{
border-top: 0.125em solid #000000;
margin: 1em 0;
border-bottom: 0;
}
</style>
<style>
.comment-block .content_textarea{
display: block;
width: 80%;
min-height: 100px;
}
.comment-block .content_textarea.hide{
display: none;
}
.comment-block .user_name{
font-size: 1.5em;
}
.comment-block p.content_text{
background-color: #fff;
border-radius: 3px;
box-shadow: 0 1px 2px -1px rgb(9 30 66 / 25%), 0 0 0 1px rgb(9 30 66 / 8%);
box-sizing: border-box;
padding: 0.5em;
overflow: hidden;
text-overflow: ellipsis;
max-width: 80%;
}
.file_block .preview_img{
position: relative;
color: #fff;
min-height: 3em;
background: gray;
}
.file_block .file_image{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
.file_block .controls{
padding-left: 1em;
}
</style>
<%= fields_for :task, @task do |f| %>
<fieldset class="form-horizontal main_fields">
<legend><h3><%= @task.task_name%></h3></legend>
<h4><%= t("ruling_timer.details") %></h4>
<div class="details_block">
<%= @task.details.html_safe %>
</div>
<hr class="custom_hr">
<div class="control-group">
<span><%= t("ruling_timer.progress") %>: <%= @task.progress %> %</span>
</div>
<hr class="custom_hr">
<h4><%= t(:file_) %></h4>
<div class="file_blocks">
<% @task.ruling_timer_files.desc(:updated_at).each do |file| %>
<% file_url = file.file.url rescue "" %>
<% next if file_url.blank? %>
<% file_name = File.basename(file_url) %>
<% ext_name = File.extname(file_name).split(".").last %>
<% ext_name = "File" if ext_name.blank? %>
<div class="file_block control-group">
<div class="control-label preview_img">
<% if ext_name.match(/(png|jpg|gif)/i) %>
<img alt="<%= file_name %>" title="<%= file_name %>" src="<%= file_url %>">
<% else %>
<div class="file_image"><%=ext_name.upcase%></div>
<% end %>
</div>
<div class="controls">
<div><a title="<%= file_name %>" href="<%=file_url%>" target="_blank" class="file_name"><%= file_name %></a></div>
<div class="description"><%=file.description%></div>
<div><span class="updated_at"><%=file.display_updated_at%></span>( <span class="user_name"><%=file.uploader.name%></span> )</div>
</div>
</div>
<% end %>
</div>
<hr class="custom_hr">
<h4><%= t("ruling_timer.comments_text") %></h4>
<div class="comments_blocks">
<p class="add-btn">
<%= hidden_field_tag 'ruling_timer_comment_field_count', f.object.ruling_timer_comments.count %>
<a id="add_comment" class="trigger btn btn-small btn-primary"><i class="icons-plus"></i> <%= t(:add) %></a>
</p>
<!-- Add -->
<div class="add-target">
</div>
<!-- Exist -->
<% if f.object && !f.object.ruling_timer_comments.blank? %>
<div class="exist">
<% f.object.ruling_timer_comments.desc(:created_at).each_with_index do |ruling_timer_comment, i| %>
<%= f.fields_for :ruling_timer_comments, ruling_timer_comment do |f| %>
<%= render :partial => 'form_comment', :object => ruling_timer_comment, :locals => {:f => f, :i => i} %>
<% end %>
<% end %>
<hr>
</div>
<% end %>
</div>
<hr class="custom_hr">
<div class="field_body">
<table class="table main-list">
<thead>
<tr>
<th><%= t("ruling_timer.task_performer") %></th>
<th><%= t("ruling_timer.task_execution_time") %></th>
</tr>
</thead>
<tbody>
<% if @task.user_ids %>
<% user_ids = @task.user_ids
user_bson_ids = user_ids.map{|id| BSON::ObjectId(id)}
%>
<% users = User.find(user_ids).index_by(&:id).slice(*user_bson_ids).values %>
<% users.each do |user| %>
<% sub_task = @task.ruling_timer_sub_tasks.where(:user=>user).first %>
<% klass = (sub_task.status == 'working' ? 'fa-play' : (sub_task.status == 'finish' ? 'fa-flag-checkered' : 'fa-pause') rescue 'fa-pause') %>
<tr>
<td><%=user.name%></td>
<td>
<% work_times = sub_task.get_work_times %>
<% work_times.each_with_index do |work_time,i| %>
<% next if i % 2 == 1 %>
<% next_time = work_times[i+1] %>
<% next_time = "Now" if next_time.nil? %>
<%= "#{work_time} ~ #{next_time}" %>
<br>
<% end %>
<div style="clear: both;"></div>
<span class="<%=sub_task.status%>_label"><i class="fa <%=klass%>"></i><%=t("ruling_timer.#{sub_task.status}")%></span>( <%=t("ruling_timer.total")%>: <%=sub_task.get_infos["work"] rescue "00:00:00" %> )
</td>
</tr>
<br>
<% end %>
<% end %>
</tbody>
</table>
</div>
</fieldset>
<%=
content_tag :div, class: "bottomnav clearfix" do
referer = request.referer rescue nil
referer = task_management_admin_ruling_timers_path if referer.blank? || request.host != URI.parse(URI.encode(referer)).host
link_to(t('edit'), edit_task_admin_ruling_timer_path , :class=>"btn") +
link_to(t('ruling_timer.back'), referer, :class=>"btn")
end %>
<style>
.bottomnav{
text-align: center;
}
</style>
<script>
$(document).on('click', '#add_comment', function(){
var new_id = $(this).prev().attr('value');
var old_id = new RegExp("new_ruling_timer_files", "g");
var on = $('.language-nav li.active').index();
var le = $(this).parent('.add-btn').prev('.add-target').children('.start-line').length;
$(this).prev().attr('value', parseInt(new_id) + 1);
$(this).parent().siblings('.add-target').prepend(("<%= escape_javascript(add_attribute 'form_comment', f, :ruling_timer_comments) %>").replace(old_id, new_id));
formTip();
});
$(document).on("click",".edit_comment",function(){
var comment_block = $(this).parents(".comment-block");
comment_block.find(".content_text").addClass("hide");
comment_block.find(".content_textarea").removeClass("hide").focus();
comment_block.find(".content_textarea").data("content",comment_block.find(".content_textarea").val());
$(this).addClass("hide");
$(this).siblings(".save_comment").removeClass("hide");
$(this).siblings(".cancel_edit_comment").removeClass("hide");
$(this).siblings(".remove_existing_record").addClass("hide");
})
$(document).on("click",".cancel_edit_comment",function(){
var _this = $(this);
var comment_block = _this.parents(".comment-block");
comment_block.find(".content_textarea").val(comment_block.find(".content_textarea").data("content"));
_this.addClass("hide");
_this.siblings(".save_comment").addClass("hide");
_this.siblings(".edit_comment").removeClass("hide");
_this.siblings(".remove_existing_record").removeClass("hide");
comment_block.find(".content_text").removeClass("hide");
comment_block.find(".content_textarea").addClass("hide");
})
$(document).on('click', '.delete_file, .delete_comment', function(){
$(this).parents('.input-prepend,.input-block').remove();
});
$(document).on('click', '.remove_existing_record', function(){
var _this = $(this);
if(confirm("<%= I18n.t(:sure?)%>")){
_this.children('.should_destroy').attr('value', 1);
var comment_block = _this.parents('.comment-block');
if( comment_block.length != 0 ){
var id = comment_block.data("id");
$.post("<%=delete_comment_admin_ruling_timers_path %>",{"id": id}).done(function(){
_this.parents('.start-line,.comment-block').remove();
})
}
}
});
$(".markdown_text:not(.ready)").each(function(i,v){
$(v).html(marked($(v).html()));
$(v).addClass("ready");
})
$(document).on("click",".save_comment",function(){
var _this = $(this);
var comment_block = _this.parents(".comment-block");
var id = comment_block.data("id");
var task_id = "<%= @task.id.to_s %>";
var content = comment_block.find(".content_textarea").val();
$.post("<%=save_comment_admin_ruling_timers_path %>",{"id": id,"content": content,"task_id": task_id}).done(function(data){
if(data["id"]){
comment_block.data("id",data["id"]);
_this.addClass("hide");
_this.siblings(".cancel_edit_comment").addClass("hide");
_this.siblings(".edit_comment").removeClass("hide");
_this.siblings(".remove_existing_record").removeClass("hide");
if(data["html"]){
comment_block.replaceWith(data["html"]);
$(".markdown_text:not(.ready)").each(function(i,v){
$(v).html(marked($(v).html()));
$(v).addClass("ready");
})
}
}
})
})
</script>
<% end %>