From b74105abc25907b2a4eb44b1fce0524c625d160f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Sun, 23 Dec 2018 20:30:09 +0100 Subject: [PATCH 1/4] Fix Date and Time display formats --- app/helpers/protocols_io_helper.rb | 4 ++-- app/models/team_zip_export.rb | 2 +- app/models/zip_export.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 60935c874..0bf7b6a0d 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -161,9 +161,9 @@ module ProtocolsIoHelper timestamps = steps.map do |step| step['modified_on'] if step['modified_on'].present? end - Time.at(timestamps.max).utc.to_datetime + I18n.l(Time.at(timestamps.max), format: :full_with_tz) rescue StandardError - Time.at(0).utc.to_datetime + I18n.l(Time.at(0), format: :full_with_tz) end # Checks so that null values are returned as zero length strings diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index a87dc11d5..41b74571f 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -30,7 +30,7 @@ class TeamZipExport < ZipExport zip_dir = FileUtils.mkdir_p(File.join(Rails.root, 'tmp/zip-ready')).first zip_file = File.new( File.join(zip_dir, - "projects_export_#{Time.now.strftime('%F_%H-%M-%S')}.zip"), + "projects_export_#{Time.now.strftime('%F_%H-%M-%S_UTC')}.zip"), 'w+' ) fill_content(zip_input_dir, data, type, options) diff --git a/app/models/zip_export.rb b/app/models/zip_export.rb index 727be849d..b9cbc7e22 100644 --- a/app/models/zip_export.rb +++ b/app/models/zip_export.rb @@ -56,7 +56,7 @@ class ZipExport < ApplicationRecord ).first zip_dir = FileUtils.mkdir_p(File.join(Rails.root, 'tmp/zip-ready')).first zip_file = File.new( - File.join(zip_dir, "export_#{Time.now.strftime('%F %H-%M-%S')}.zip"), + File.join(zip_dir, "export_#{Time.now.strftime('%F %H-%M-%S_UTC')}.zip"), 'w+' ) fill_content(zip_input_dir, data, type, options) From b64df7d8cc177cc60b402c0ec2f272f088379f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Tue, 8 Jan 2019 06:29:37 +0100 Subject: [PATCH 2/4] Fix additional Date and Time display formats --- app/views/my_module_comments/_comment.html.erb | 2 +- app/views/project_comments/_comment.html.erb | 2 +- .../_import_json_protocol_preview_modal.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index f2510df6e..d79ade7b9 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -1,5 +1,5 @@
- <%= l comment.created_at, format: '%H:%M' %> + <%= l comment.created_at, format: :time %> <% if can_manage_comment_in_module?(comment.becomes(Comment)) %> From 8070b7f8b5c57fc87b2b98914aa661200d68906b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Tue, 8 Jan 2019 08:07:24 +0100 Subject: [PATCH 3/4] Fix Date and Time display formats on JS side --- .../protocols/import_export/import.js.erb | 25 +++++++++++++++++-- app/controllers/application_controller.rb | 10 ++++++++ config/routes.rb | 6 +++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/protocols/import_export/import.js.erb b/app/assets/javascripts/protocols/import_export/import.js.erb index b4845bddf..6ecc22fdb 100644 --- a/app/assets/javascripts/protocols/import_export/import.js.erb +++ b/app/assets/javascripts/protocols/import_export/import.js.erb @@ -115,8 +115,29 @@ function importProtocolFromFile( $("#protocol_authors").val($(this).children("authors").text()); $("#import_protocol_description").val($(this).children("description").text()); } - $("#protocol_created_at").val($(this).children("created_at").text()); - $("#protocol_updated_at").val($(this).children("updated_at").text()); + + $.ajax({ + url: "/helpers/to_user_date_format.json", + type: "GET", + data: { "timestamp": $(this).children("created_at").text(), + "ts_format": "full" }, + dataType: "json", + async: false, + success: function (data) { + $("#protocol_created_at").val(data.ts); + } + }); + $.ajax({ + url: "/helpers/to_user_date_format.json", + type: "GET", + data: { "timestamp": $(this).children("updated_at").text(), + "ts_format": "full" }, + dataType: "json", + async: false, + success: function (data) { + $("#protocol_updated_at").val(data.ts); + } + }); }); // PREVIEW diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 607e5185c..da2720603 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -36,6 +36,16 @@ class ApplicationController < ActionController::Base Team.find_by_id(current_user.current_team_id) end + def to_user_date_format + ts = I18n.l(Time.parse(params[:timestamp]), + format: params[:ts_format].to_sym) + respond_to do |format| + format.json do + render json: { ts: ts }, status: :ok + end + end + end + protected def render_403(style = 'danger') diff --git a/config/routes.rb b/config/routes.rb index 77462cbe8..9ca15b04f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,12 @@ Rails.application.routes.draw do get 'forbidden', to: 'application#forbidden', as: 'forbidden' get 'not_found', to: 'application#not_found', as: 'not_found' + # JS backend helpers + get 'helpers/to_user_date_format', + to: 'application#to_user_date_format', + as: 'to_user_date_format', + defaults: { format: 'json' } + # Settings resources :users, only: :index # needed for testing signup # needed for testing edit passowrd From 838455af0d7a7d02c5145eed6fde0de9aaeff5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Zrim=C5=A1ek?= Date: Sat, 12 Jan 2019 19:28:45 +0100 Subject: [PATCH 4/4] Fix protocols.io Date handling at import --- app/helpers/protocols_io_helper.rb | 4 ++-- .../_import_json_protocol_preview_modal.html.erb | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/helpers/protocols_io_helper.rb b/app/helpers/protocols_io_helper.rb index 0bf7b6a0d..db52f3df1 100644 --- a/app/helpers/protocols_io_helper.rb +++ b/app/helpers/protocols_io_helper.rb @@ -161,9 +161,9 @@ module ProtocolsIoHelper timestamps = steps.map do |step| step['modified_on'] if step['modified_on'].present? end - I18n.l(Time.at(timestamps.max), format: :full_with_tz) + I18n.l(Time.at(timestamps.max), format: :full) rescue StandardError - I18n.l(Time.at(0), format: :full_with_tz) + I18n.l(Time.at(0), format: :full) end # Checks so that null values are returned as zero length strings diff --git a/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb b/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb index 72dac3dd4..8bbc35326 100644 --- a/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb +++ b/app/views/protocols/import_export/_import_json_protocol_preview_modal.html.erb @@ -60,9 +60,7 @@ <% display_last_modified=eval_last_modified(@json_object['steps']) %> - <%= f.text_field :last_modified, :value => - I18n.l(display_last_modified, format: :full), readonly: true, class: - "form-control" %> + <%= f.text_field :last_modified, :value => display_last_modified, readonly: true, class: "form-control" %>