commit 1be1ef10ebd32623c0638c7405b33c304091f05e Author: Bohung Date: Wed Jul 21 15:37:06 2021 +0800 Finish first version of ruling timer. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e157571 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.bundle/ +log/*.log +pkg/ +test/dummy/db/*.sqlite3 +test/dummy/db/*.sqlite3-journal +test/dummy/log/*.log +test/dummy/storage/ +test/dummy/tmp/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..8c7e7f2 --- /dev/null +++ b/Gemfile @@ -0,0 +1,15 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +# Declare your gem's dependencies in sync_ntnu_personal_data.gemspec. +# Bundler will treat runtime dependencies like base dependencies, and +# development dependencies will be added by default to the :development group. +gemspec + +# Declare any dependencies that are still in development here instead of in +# your gemspec. These might include edge Rails or gems from your path or +# Git. Remember to move these dependencies to your gemspec before releasing +# your gem to rubygems.org. + +# To use a debugger +# gem 'byebug', group: [:development, :test] diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..5fe3c6c --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright 2021 BOHUNG,CHIU + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..64369ce --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Ruling Timer for users \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..885cf69 --- /dev/null +++ b/Rakefile @@ -0,0 +1,32 @@ +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end + +require 'rdoc/task' + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'SyncNtnuPersonalData' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.md') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) +load 'rails/tasks/engine.rake' + +load 'rails/tasks/statistics.rake' + +require 'bundler/gem_tasks' + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + t.libs << 'test' + t.pattern = 'test/**/*_test.rb' + t.verbose = false +end + +task default: :test diff --git a/app/assets/images/ruling_timer/.keep b/app/assets/images/ruling_timer/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/ruling_timer/.keep b/app/assets/stylesheets/ruling_timer/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/.keep b/app/controllers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/admin/ruling_timers_controller.rb b/app/controllers/admin/ruling_timers_controller.rb new file mode 100644 index 0000000..8cc4d4c --- /dev/null +++ b/app/controllers/admin/ruling_timers_controller.rb @@ -0,0 +1,206 @@ +class Admin::RulingTimersController < OrbitAdminController + include Admin::RulingTimersHelper + before_action ->(module_app = @app_title) { set_variables module_app } + before_action :set_weekdays + def initialize + super + @app_title = "ruling_timer" + end + def index + user = current_user + @ruling_timer_temp = RulingTimerTemp.where(:user=>user).first + @ruling_timer_history = [] + all_count = 0 + per = 10 + page = params[:page].to_i + if @ruling_timer_temp + @ruling_timer_history = RulingTimerHistory.where(:user=>user).desc(:created_at) + all_count += (1 + @ruling_timer_history.count) + if page <= 1 + @ruling_timer_history = @ruling_timer_history.page(0).per(per - 1) + else + @ruling_timer_history = @ruling_timer_history.limit(per).skip(per * page - 1) + @ruling_timer_temp = nil + end + end + @ruling_pager = RulingPager.new(:count=>all_count,:page=>page,:per=>per) + end + def timer_management + @timer_temps = RulingTimerTemp.all.page(params[:page]).per(15) + @active_users = @timer_temps.map{|t| t.user} + end + def task_management + @tasks = RulingTimerTask.all.page(params[:page]).per(10) + end + def work_history + user = User.find(params[:id]) rescue nil + @ruling_timer_temp = RulingTimerTemp.where(:user=>user).first + @ruling_timer_history = [] + all_count = 0 + per = 10 + page = params[:page].to_i + if @ruling_timer_temp + @ruling_timer_history = RulingTimerHistory.where(:user=>user).desc(:created_at) + all_count += (1 + @ruling_timer_history.count) + if page <= 1 + @ruling_timer_history = @ruling_timer_history.page(0).per(per - 1) + else + @ruling_timer_history = @ruling_timer_history.limit(per).skip(per * page - 1) + @ruling_timer_temp = nil + end + end + @ruling_pager = RulingPager.new(:count=>all_count,:page=>page,:per=>per) + @user_name = user.name + render "index" + end + def edit_temp_timer + @timer = RulingTimerTemp.find(params[:id]) rescue nil + if @timer.nil? + redirect_to admin_ruling_timers_path and return + end + render "edit_timer" + end + def edit_timer + @timer = RulingTimerHistory.find(params[:id]) rescue nil + if @timer.nil? + redirect_to admin_ruling_timers_path and return + end + end + def update_timer + @timer = nil + if params[:type] == "temp" + @timer = RulingTimerTemp.find(params[:id]) + else + @timer = RulingTimerHistory.find(params[:id]) + end + @timer_params = timer_params + date = @timer.date.split(" ")[0] + @timer_params[:work_times] = @timer_params[:work_times].to_a.map do |t| + if t.blank? + nil + else + DateTime.parse("#{date} #{t}#{@timer.time_offset}").utc + end + end.compact + @timer.update_attributes(@timer_params) + @timer.fix_work_times + redirect_to params[:referer_url] + end + def add_task + @task = RulingTimerTask.new + @users = User.all.where(:user_name.ne=>"rulingcom") + end + def edit_task + @task = RulingTimerTask.find(params[:id]) + @users = User.all.where(:user_name.ne=>"rulingcom") + end + def create_task + @task = RulingTimerTask.create(task_params) + redirect_to params[:referer_url] + end + def update_task + @task = RulingTimerTask.find(params[:id]) + @task.update_attributes(task_params) + redirect_to params[:referer_url] + end + def delete_task + if params[:confirm_delete] + RulingTimerTask.where(:id=>params[:id]).destroy + render :json => {:success=>true} + end + end + def view_task + @task = RulingTimerTask.find(params[:id]) + end + def delete_history + if params[:confirm_delete] + if params[:type] == 'temp' + RulingTimerTemp.where(:id=>params[:id]).destroy + else + RulingTimerHistory.where(:id=>params[:id]).destroy + end + render :json => {:success=>true} + end + end + def add_history + @user = nil + if params[:id] == "current_user" + params[:id] = current_user.id.to_s + @user = current_user + else + @user = User.find(params[:id]) + end + @history = RulingTimerHistory.new(:user_id=>params[:id]) + end + def create_history + @history_params = history_params + user = User.find(@history_params[:user_id]) + @old_historys = RulingTimerHistory.where(:date=>@history_params[:date],:user=>user).to_a + RulingTimerTemp.where(:date=>@history_params[:date],:user=>user).to_a + if @old_historys.count == 0 + if RulingTimerTemp.where(:user=>user).count == 0 + @history = RulingTimerTemp.create(@history_params) + else + @history = RulingTimerHistory.create(@history_params) + end + @history.recalc_all + @history.fix_work_times + else + @old_history = @old_historys.first + @old_history.merge_work_times(@history_params[:work_times]) + end + redirect_to params[:referer_url] + end + def history_params + history_params = params.require(:ruling_timer_history).permit! + date = history_params[:date] + time_offset = history_params[:time_offset] + history_params[:work_times] =[] if history_params[:work_times].nil? + first_time = history_params[:work_times].first + first_time = "00:00:00" if first_time.blank? + history_params[:work_times] = history_params[:work_times].map do |t| + if t.blank? + nil + else + DateTime.parse("#{date} #{t}#{time_offset}").utc + end + end.compact + history_params[:date] = DateTime.parse(date).strftime("%Y/%m/%d %w") + history_params[:created_at] = DateTime.parse(date + " " + first_time + time_offset).utc + history_params + end + def task_params + task_params = params.require(:ruling_timer_task).permit! + task_params[:user_ids] = [] if task_params[:user_ids].nil? + task_params + end + def timer_params + if params[:type] == "temp" + params.require(:ruling_timer_temp).permit! + else + params.require(:ruling_timer_history).permit! + end + end + def set_weekdays + @weekdays = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"] + @weekdays.map!{|d| I18n.t("ruling_timer.week_days.#{d}")} + end + class RulingPager + attr_accessor :count,:page,:per + def initialize(attrs) + if attrs.class == Hash + attrs.each do |k,v| + self.send("#{k}=",v) + end + end + end + def current_page + self.page.to_i + end + def limit_value + self.per + end + def total_pages + (self.count / self.per).ceil + end + end +end \ No newline at end of file diff --git a/app/controllers/ruling_timers_controller.rb b/app/controllers/ruling_timers_controller.rb new file mode 100644 index 0000000..3cffa4f --- /dev/null +++ b/app/controllers/ruling_timers_controller.rb @@ -0,0 +1,137 @@ +class RulingTimersController < ApplicationController + before_action :set_timer + def save_work_times + @ruling_timer_temp.update_work_times(params[:work_times]) + @ruling_timer_temp.recalc_all + render :json => @ruling_timer_temp.to_json + end + def get_work_times + render :json => @ruling_timer_temp.get_work_times(true) + end + def start + render :json => @ruling_timer_temp.start(params[:timer_offset]) + end + def stop + render :json => @ruling_timer_temp.stop + end + def rest + render :json => @ruling_timer_temp.rest + end + def set_summary + begin + @ruling_timer_temp.summary = params[:summary] + @ruling_timer_temp.save! + render :json => {"success"=>true} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def add_task + begin + @ruling_timer_temp.tasks << params[:task] + task = RulingTimerTask.create(:task_name=>params[:task],:user_ids=>[current_user.id.to_s]) + sub_task = task.ruling_timer_sub_tasks.first + @ruling_timer_temp.sub_task_ids << sub_task.id.to_s + @ruling_timer_temp.save! + if @ruling_timer_temp.status == "working" + sub_task.start(@ruling_timer_temp.time_offset) + else + sub_task.update(:time_offset =>@ruling_timer_temp.time_offset) + end + render :json => {"success"=>true,"task-id"=>sub_task.id,"task"=>sub_task.task_name} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def add_task_from_list + begin + task = RulingTimerTask.find(params[:task_id]) + if !(task.user_ids.include?(current_user.id.to_s)) + task.user_ids << current_user.id.to_s + task.save + end + sub_task = task.ruling_timer_sub_tasks.where(:user=>current_user).first + if !(@ruling_timer_temp.sub_task_ids.include?(sub_task.id.to_s)) + @ruling_timer_temp.sub_task_ids << sub_task.id.to_s + @ruling_timer_temp.tasks << task.task_name + @ruling_timer_temp.save! + end + if @ruling_timer_temp.status == "working" + sub_task.start(@ruling_timer_temp.time_offset) + else + sub_task.update(:time_offset =>@ruling_timer_temp.time_offset) + end + render :json => {"success"=>true,"task-id"=>sub_task.id,"task"=>sub_task.task_name} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def remove_task + begin + @ruling_timer_temp.remove_task(params[:task_id]) + render :json => {"success"=>true} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def start_task + task = RulingTimerSubTask.find(params[:task_id]) + render :json => task.start + end + def stop_task + render :json => task.stop + end + def set_task_status + begin + idx = @ruling_timer_temp.sub_task_ids.index(params[:task_id]) + if idx + task = RulingTimerSubTask.find(params[:task_id]) + if params[:status].to_i == 0 + @ruling_timer_temp.tasks_finished.delete(idx) + task.start + else + @ruling_timer_temp.tasks_finished << idx + @ruling_timer_temp.tasks_finished.uniq! + task.finish + end + @ruling_timer_temp.save! + end + render :json => {"success"=>true} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def add_event + begin + @ruling_timer_temp.add_event(*params[:event]) + render :json => {"success"=>true} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def delete_event + begin + @ruling_timer_temp.delete_event(params[:event_idx].to_i) + render :json => {"success"=>true} + rescue => e + puts [e,e.backtrace] + render :json => {"success"=>false} + end + end + def set_timer + @ruling_timer_temp = nil + user = (current_user rescue nil) + if (user rescue false) + @ruling_timer_temp = RulingTimerTemp.where(:user=>user).first + if @ruling_timer_temp.nil? + @ruling_timer_temp = RulingTimerTemp.create(:user=>user) + end + end + end +end \ No newline at end of file diff --git a/app/helpers/.keep b/app/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/helpers/admin/ruling_timers_helper.rb b/app/helpers/admin/ruling_timers_helper.rb new file mode 100644 index 0000000..054ee0e --- /dev/null +++ b/app/helpers/admin/ruling_timers_helper.rb @@ -0,0 +1,2 @@ +module Admin::RulingTimersHelper +end \ No newline at end of file diff --git a/app/helpers/ruling_timers_helper.rb b/app/helpers/ruling_timers_helper.rb new file mode 100644 index 0000000..0027998 --- /dev/null +++ b/app/helpers/ruling_timers_helper.rb @@ -0,0 +1,2 @@ +module RulingTimersHelper +end \ No newline at end of file diff --git a/app/mailers/.keep b/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/.keep b/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/ruling_timer_history.rb b/app/models/ruling_timer_history.rb new file mode 100644 index 0000000..b9de4ae --- /dev/null +++ b/app/models/ruling_timer_history.rb @@ -0,0 +1,170 @@ +class RulingTimerHistory + include Mongoid::Document + include Mongoid::Timestamps + field :work_time_str, type: String, default: "00:00:00" + field :rest_time_str, type: String, default: "00:00:00" + field :all_work_times_seconds, type: Integer, default: 0 + field :all_rest_times_seconds, type: Integer, default: 0 + field :work_times, type: Array, default: [] + field :rest_times, type: Array, default: [] + field :sub_task_ids, type: Array, default: [] #store RulingTimerSubTask id + field :tasks, type: Array, default: [] #store name only + field :tasks_finished, type: Array, default: [] #store index only + field :summary, type: String, default: "" + field :time_offset, type: String, default: "+8" + field :events, type: Array, default: [] + field :date, type: String, default: "" + belongs_to :user + def fix_work_times(store=true) + time_now = DateTime.now.utc + work_times_range = self.work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + work_times_range = eliminate_intersection(work_times_range) + new_work_times_range = merge_ranges(work_times_range.uniq).flat_map{|range| [range.first,range.last]} + new_work_times_range = new_work_times_range[0...-1] if new_work_times_range.last == time_now + self.work_times = new_work_times_range + self.calc("work_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save if store + self.work_times + end + def merge_work_times(new_work_times,store=true) + time_now = DateTime.now.utc + work_times_range = self.work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + new_work_times_range = new_work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + work_times_range = eliminate_intersection(work_times_range) + new_work_times_range = eliminate_intersection(new_work_times_range) + new_work_times_range = work_times_range + new_work_times_range + new_work_times_range = eliminate_intersection(new_work_times_range).sort_by{|range| range.first.to_i} + new_work_times_range = merge_ranges(new_work_times_range.uniq).flat_map{|range| [range.first,range.last]} + new_work_times_range = new_work_times_range[0...-1] if new_work_times_range.last == time_now + self.work_times = new_work_times_range + self.calc("work_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save if store + self.work_times + end + def merge_ranges(ranges) + (0...(ranges.count)).each do |i| + next if ranges[i+1].nil? + if ranges[i].last == ranges[i+1].first + ranges[i+1] = (ranges[i].first .. ranges[i+1].last) + ranges[i] = nil + end + end + ranges.compact + end + def eliminate_intersection(times_range) + times_range = times_range.sort_by{|range| range.first.to_i} + times_range.each_with_index do |range,i| + next if range.nil? + intersects = times_range[i+1..-1].map{|r| range & r} + if intersects.compact.count != 0 + intersects.each_with_index do |intersect,j| + next if intersect.nil? + if range.last > intersect.last #overlap all + times_range[i+1+j] = nil + else + if range.first == intersect.first + times_range[i] = nil + else + times_range[i] = (range.first..intersect.first) + end + end + end + end + end + times_range.compact + end + def update_task_name(task_id,new_name) + idx = self.sub_task_ids.index(task_id) + self.tasks[idx] = new_name + self.save + end + def remove_task(task_id) + sub_task = RulingTimerSubTask.find(task_id) rescue nil + idx = self.sub_task_ids.index(task_id) + self.sub_task_ids.delete(task_id) + self.tasks.delete_at(idx) + self.tasks_finished = self.tasks_finished.to_a.map do |task_idx| + if task_idx == idx + nil + elsif task_idx > idx + task_idx - 1 + else + task_idx + end + end.compact + self.save! + sub_task.stop if sub_task + end + def get_work_times(display_seond=false) + work_times = self.work_times.clone + if display_seond + time_format = "%H:%M:%S" + else + time_format = "%H:%M" + end + work_times.map!{|t| convert_datetime(t).new_offset(self.time_offset).strftime(time_format)} + end + def convert_datetime(time) + if time.class == Time + return time.to_datetime + elsif time.class == DateTime + return time + elsif time.class == String + return DateTime.parse(time) + else + return Time.at(time).to_datetime #time is seconds + end + end + def get_infos + return {"work" => self.work_time_str, "rest" => self.rest_time_str} + end + def calc(field_name,padding=true,recalc=false) + time_infos = self.send(field_name).clone rescue [] + record_field_name = "all_#{field_name}_seconds" + tmp_seconds = self.send(record_field_name) + all_seconds = 0 + start_index = 0 + if !recalc + all_seconds = tmp_seconds + start_index = time_infos.count - 1 + start_index -= (start_index % 2) + time_infos = time_infos[start_index..-1].to_a + end + time_infos.push(DateTime.now.utc) if (padding && time_infos.count % 2 == 1) + time_infos.each_with_index do |t,i| + if i % 2 == 0 + next_t = time_infos[i+1] + if !next_t.nil? + all_seconds += ((convert_datetime(next_t) - convert_datetime(t)) * 1.day).round + else + break + end + end + end + self.send("#{record_field_name}=",all_seconds) + return all_seconds + end + def recalc_all + self.calc("work_times",false,true) + self.calc("rest_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + self.save + return self.to_json + end + def getPaddedComp(comp) + return ((comp.to_i < 10) ? ('0' + comp.to_s) : comp.to_s) + end + def transform_second_to_time(seconds) + seconds = 0 if seconds.nil? + hour = 3600 + minute = 60 + total_hour = getPaddedComp(seconds / hour) + rest_seconds = seconds % hour + total_minute = getPaddedComp(rest_seconds / minute) + total_second = getPaddedComp(rest_seconds % minute) + return (total_hour + ":" + total_minute + ":" + total_second) + end +end \ No newline at end of file diff --git a/app/models/ruling_timer_sub_task.rb b/app/models/ruling_timer_sub_task.rb new file mode 100644 index 0000000..4a3f233 --- /dev/null +++ b/app/models/ruling_timer_sub_task.rb @@ -0,0 +1,146 @@ +class RulingTimerSubTask + include Mongoid::Document + include Mongoid::Timestamps + field :task_name, type: String, default: "" + field :work_time_str, type: String, default: "00:00:00" + field :all_work_times_seconds, type: Integer, default: 0 + field :work_times, type: Array, default: [] + field :status, type: String, default: "stop" # stop, working, finish + field :time_offset, type: String, default: "+8" + belongs_to :ruling_timer_task + belongs_to :user + after_destroy do |record| + id = record.id.to_s + timers = RulingTimerTemp.where(:sub_task_ids=>id).to_a + RulingTimerHistory.where(:sub_task_ids=>id).to_a + timers.each do |timer| + timer.remove_task(id) + end + end + after_save do |record| + if record.task_name_changed? + id = record.id.to_s + timers = RulingTimerTemp.where(:sub_task_ids=>id).to_a + RulingTimerHistory.where(:sub_task_ids=>id).to_a + timers.each do |timer| + timer.update_task_name(id,record.task_name) + end + end + end + def get_work_times(display_seond=false) + work_times = self.work_times.clone + if display_seond + time_format = "%Y/%m/%d %H:%M:%S" + else + time_format = "%Y/%m/%d %H:%M" + end + work_times.map!{|t| convert_datetime(t).new_offset(self.time_offset).strftime(time_format)} + end + def start(offset="+8") + self.time_offset = offset + self.status = "working" + time_now = DateTime.now.utc + if self.work_times.count % 2 == 0 + self.work_times.push(time_now) + end + self.calc("work_times",false) + self.save + self.ruling_timer_task.update(:is_finished => false) + return self.to_json + end + def reset_all(except_fields=[]) + unless self.new_record? + change_fields = self.changes.except(*(except_fields.map{|f| f.to_s})) + change_fields.each do |k,v| + self.send("#{k}=",v[0]) + end + end + end + def stop + time_now = DateTime.now.utc + if self.work_times.count % 2 == 1 + self.work_times.push(time_now) + end + self.status = "stop" + self.calc("work_times",false) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save + return self.to_json + end + def finish + time_now = DateTime.now.utc + if self.work_times.count % 2 == 1 + self.work_times.push(time_now) + end + self.status = "finish" + self.calc("work_times") + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save + self.ruling_timer_task.update(:is_finished => true) + return self.to_json + end + def recalc_all + self.calc("work_times",true,true) + self.save + return self.to_json + end + def to_json + return {"work" => self.all_work_times_seconds} + end + def get_infos + self.calc("work_times") + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.reset_all([:work_time_str]) + return {"work" => self.work_time_str} + end + def convert_datetime(time) + if time.class == Time + return time.to_datetime + elsif time.class == DateTime + return time + elsif time.class == String + return DateTime.parse(time) + else + return Time.at(time).to_datetime #time is seconds + end + end + def getPaddedComp(comp) + return ((comp.to_i < 10) ? ('0' + comp.to_s) : comp.to_s) + end + def transform_second_to_time(seconds) + hour = 3600 + minute = 60 + total_hour = getPaddedComp(seconds / hour) + rest_seconds = seconds % hour + total_minute = getPaddedComp(rest_seconds / minute) + total_second = getPaddedComp(rest_seconds % minute) + return (total_hour + ":" + total_minute + ":" + total_second) + end + def calc(field_name,padding=true,recalc=false) + time_infos = self.send(field_name).clone rescue [] + record_field_name = "all_#{field_name}_seconds" + tmp_seconds = self.send(record_field_name) + all_seconds = 0 + start_index = 0 + if !recalc + all_seconds = tmp_seconds + start_index = time_infos.count - 1 + start_index -= (start_index % 2) + time_infos = time_infos[start_index..-1].to_a + if !(self.send("#{field_name}_changed?")) && time_infos.count != 1 + return all_seconds + end + end + time_infos.push(DateTime.now.utc) if (padding && time_infos.count % 2 == 1) + time_infos.each_with_index do |t,i| + if i % 2 == 0 + next_t = time_infos[i+1] + if !next_t.nil? + all_seconds += ((convert_datetime(next_t) - convert_datetime(t)) * 1.day).round + else + break + end + end + end + self.send("#{record_field_name}=",all_seconds) + return all_seconds + end +end \ No newline at end of file diff --git a/app/models/ruling_timer_task.rb b/app/models/ruling_timer_task.rb new file mode 100644 index 0000000..281043b --- /dev/null +++ b/app/models/ruling_timer_task.rb @@ -0,0 +1,28 @@ +class RulingTimerTask + include Mongoid::Document + include Mongoid::Timestamps + field :task_name, type: String, default: "" + has_many :ruling_timer_sub_tasks, :autosave => true, :dependent => :destroy + field :user_ids, type: Array, default: [] + field :is_finished, type: Boolean, default: false + def users + User.where(:id.in=>self.user_ids) + end + after_save do |record| + if record.user_ids_changed? + delete_user_ids = record.user_ids_was.to_a - record.user_ids.to_a + add_user_ids = record.user_ids.to_a - record.user_ids_was.to_a + delete_user_ids.each do |user| + self.ruling_timer_sub_tasks.where(:user=>user).destroy + end + add_user_ids.each do |user| + self.ruling_timer_sub_tasks.create(:user=>user,:task_name=>task_name) + end + end + if record.task_name_changed? + self.ruling_timer_sub_tasks.each do |sub_task| + sub_task.update(:task_name=>task_name) + end + end + end +end \ No newline at end of file diff --git a/app/models/ruling_timer_temp.rb b/app/models/ruling_timer_temp.rb new file mode 100644 index 0000000..2b1b448 --- /dev/null +++ b/app/models/ruling_timer_temp.rb @@ -0,0 +1,358 @@ +class RulingTimerTemp + include Mongoid::Document + include Mongoid::Timestamps + field :status, type: String, default: "stop" # working, rest, stop + field :work_time_str, type: String, default: "00:00:00" + field :rest_time_str, type: String, default: "00:00:00" + field :all_work_times_seconds, type: Integer, default: 0 + field :all_rest_times_seconds, type: Integer, default: 0 + field :work_times, type: Array, default: [] + field :rest_times, type: Array, default: [] + field :sub_task_ids, type: Array, default: [] #store RulingTimerSubTask id + field :tasks, type: Array, default: [] #store name only + field :tasks_finished, type: Array, default: [] #store index only + field :summary, type: String, default: "" + field :time_offset, type: String, default: "+8" + field :events, type: Array, default: [] + field :date, type: String, default: "" + belongs_to :user + before_create do |record| + time_now = DateTime.now.utc + record.date = time_now.new_offset(self.time_offset).strftime("%Y/%m/%d %w") if record.date.blank? + end + def update_work_times(work_times,store=true) + work_times = work_times.to_a + time_now = DateTime.now.utc + self.date = time_now.new_offset(self.time_offset).strftime("%Y/%m/%d %w") if self.date.blank? + date_str = self.date.split(" ")[0] + work_times = work_times.to_a.map do |t| + if t.blank? + nil + else + DateTime.parse("#{date_str} #{t}#{self.time_offset}").utc + end + end + self.work_times = work_times + self.save if store + self.work_times + end + def fix_work_times(store=true) + time_now = DateTime.now.utc + work_times_range = self.work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + work_times_range = eliminate_intersection(work_times_range) + new_work_times_range = merge_ranges(work_times_range.uniq).flat_map{|range| [range.first,range.last]} + new_work_times_range = new_work_times_range[0...-1] if new_work_times_range.last == time_now + self.work_times = new_work_times_range + self.calc("work_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save if store + self.work_times + end + def merge_work_times(new_work_times,store=true) + time_now = DateTime.now.utc + work_times_range = self.work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + new_work_times_range = new_work_times.each_slice(2).to_a.map{|a,b| convert_datetime(a)..(b.nil? ? time_now : convert_datetime(b))} + work_times_range = eliminate_intersection(work_times_range) + new_work_times_range = eliminate_intersection(new_work_times_range) + new_work_times_range = work_times_range + new_work_times_range + new_work_times_range = eliminate_intersection(new_work_times_range).sort_by{|range| range.first.to_i} + new_work_times_range = merge_ranges(new_work_times_range.uniq).flat_map{|range| [range.first,range.last]} + new_work_times_range = new_work_times_range[0...-1] if new_work_times_range.last == time_now + self.work_times = new_work_times_range + self.calc("work_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.save if store + self.work_times + end + def merge_ranges(ranges) + (0...(ranges.count)).each do |i| + next if ranges[i+1].nil? + if ranges[i].last == ranges[i+1].first + ranges[i+1] = (ranges[i].first .. ranges[i+1].last) + ranges[i] = nil + end + end + ranges.compact + end + def eliminate_intersection(times_range) + times_range = times_range.sort_by{|range| range.first.to_i} + times_range.each_with_index do |range,i| + next if range.nil? + intersects = times_range[i+1..-1].map{|r| range & r} + if intersects.compact.count != 0 + intersects.each_with_index do |intersect,j| + next if intersect.nil? + if range.last > intersect.last #overlap all + times_range[i+1+j] = nil + else + if range.first == intersect.first + times_range[i] = nil + else + times_range[i] = (range.first..intersect.first) + end + end + end + end + end + times_range.compact + end + def update_task_name(task_id,new_name) + idx = self.sub_task_ids.index(task_id) + self.tasks[idx] = new_name + self.save + end + def remove_task(task_id) + sub_task = RulingTimerSubTask.find(task_id) rescue nil + idx = self.sub_task_ids.index(task_id) + self.sub_task_ids.delete(task_id) + self.tasks.delete_at(idx) + self.tasks_finished = self.tasks_finished.to_a.map do |task_idx| + if task_idx == idx + nil + elsif task_idx > idx + task_idx - 1 + else + task_idx + end + end.compact + self.save! + sub_task.stop if sub_task + end + def get_work_times(display_seond=false) + work_times = self.work_times.clone + if display_seond + time_format = "%H:%M:%S" + else + time_format = "%H:%M" + end + work_times.map!{|t| convert_datetime(t).new_offset(self.time_offset).strftime(time_format)} + end + def get_last_work_time + last_work_time = self.work_times.last + if last_work_time.nil? + last_work_time = DateTime.now.utc.new_offset(self.time_offset) + else + last_work_time = convert_datetime(last_work_time).new_offset(self.time_offset) + end + return last_work_time + end + def check_and_store + unless self.new_record? + time_now = DateTime.now.utc + if time_now.new_offset(self.time_offset).strftime('%Y/%m/%d') != self.get_last_work_time.strftime('%Y/%m/%d') + self.stop + self.store + end + date_str = time_now.new_offset(self.time_offset).strftime("%Y/%m/%d %w") + if self.date != date_str + self.save + end + end + end + def start(offset=nil) + self.time_offset = offset if offset + self.check_and_store + self.status = "working" + time_now = DateTime.now.utc + self.date = time_now.new_offset(self.time_offset).strftime("%Y/%m/%d %w") + if self.work_times.count % 2 == 0 + self.work_times.push(time_now) + end + if self.rest_times.count % 2 == 1 + self.rest_times.push(time_now) + end + self.calc("work_times",false) + self.calc("rest_times",false) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + self.save + self.start_all_task + return self.to_json + end + def reset_all(except_fields=[]) + unless self.new_record? + change_fields = self.changes.except(*(except_fields.map{|f| f.to_s})) + change_fields.each do |k,v| + self.send("#{k}=",v[0]) + end + end + end + def start_all_task + temp_task_ids = self.sub_task_ids + if self.tasks_finished.count != 0 + temp_task_ids = temp_task_ids.select.with_index{|id,i| !(self.tasks_finished.include?(i))} + end + temp_tasks = RulingTimerSubTask.where(:id.in=>temp_task_ids).to_a + temp_tasks.each{|task| task.start} + end + def stop_all_task + temp_task_ids = self.sub_task_ids + if self.tasks_finished.count != 0 + temp_task_ids = temp_task_ids.select.with_index{|id,i| !(self.tasks_finished.include?(i))} + end + temp_tasks = RulingTimerSubTask.where(:id.in=>temp_task_ids).to_a + temp_tasks.each{|task| task.stop} + end + def stop + time_now = DateTime.now.utc + if self.work_times.count % 2 == 1 + self.work_times.push(time_now) + end + self.status = "stop" + self.calc("work_times",false) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + self.save + self.stop_all_task + return self.to_json + end + def rest + self.status = "rest" + time_now = DateTime.now.utc + if self.work_times.count % 2 == 1 + self.work_times.push(time_now) + end + if self.rest_times.count % 2 == 0 + self.rest_times.push(time_now) + end + self.calc("work_times",false) + self.calc("rest_times",false) + self.save + self.stop_all_task + return self.to_json + end + def recalc_all + self.calc("work_times",false,true) + self.calc("rest_times",false,true) + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + self.save + return self.to_json + end + def to_json + self.calc("work_times") + self.calc("rest_times") + work_seconds = self.all_work_times_seconds + rest_seconds = self.all_rest_times_seconds + self.reset_all + return {"work" => work_seconds, "rest" => rest_seconds} + end + def get_infos + self.calc("work_times") + self.calc("rest_times") + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + self.reset_all([:work_time_str,:rest_time_str]) + return {"work" => self.work_time_str, "rest" => self.rest_time_str} + end + def convert_datetime(time) + if time.class == Time + return time.to_datetime + elsif time.class == DateTime + return time + elsif time.class == String + return DateTime.parse(time) + else + return Time.at(time).to_datetime #time is seconds + end + end + def getPaddedComp(comp) + return ((comp.to_i < 10) ? ('0' + comp.to_s) : comp.to_s) + end + def transform_second_to_time(seconds) + seconds = 0 if seconds.nil? + hour = 3600 + minute = 60 + total_hour = getPaddedComp(seconds / hour) + rest_seconds = seconds % hour + total_minute = getPaddedComp(rest_seconds / minute) + total_second = getPaddedComp(rest_seconds % minute) + return (total_hour + ":" + total_minute + ":" + total_second) + end + def calc(field_name,padding=true,recalc=false) + time_infos = self.send(field_name).clone rescue [] + record_field_name = "all_#{field_name}_seconds" + tmp_seconds = self.send(record_field_name) + all_seconds = 0 + start_index = 0 + if !recalc + all_seconds = tmp_seconds + start_index = time_infos.count - 1 + start_index -= (start_index % 2) + time_infos = time_infos[start_index..-1].to_a + if !(self.send("#{field_name}_changed?")) && time_infos.count != 1 + return all_seconds + end + end + time_infos.push(DateTime.now.utc) if (padding && time_infos.count % 2 == 1) + time_infos.each_with_index do |t,i| + if i % 2 == 0 + next_t = time_infos[i+1] + if !next_t.nil? + all_seconds += ((convert_datetime(next_t) - convert_datetime(t)) * 1.day).round + else + break + end + end + end + self.send("#{record_field_name}=",all_seconds) + return all_seconds + end + def add_event(startt,endt,event) + self.events << {"start"=>startt,"end"=> endt,"event"=>event} + self.save + end + def delete_event(idx) + self.events.delete_at(idx) + self.save + end + def store + self.calc("work_times") + self.calc("rest_times") + self.work_time_str = transform_second_to_time(self.all_work_times_seconds) + self.rest_time_str = transform_second_to_time(self.all_rest_times_seconds) + fields = self.fields.except("_id","created_at","updated_at","status").keys + if self.all_work_times_seconds != 0 || self.all_rest_times_seconds != 0 + ruling_timer_history = RulingTimerHistory.new + fields.each do |f| + field_name = f + if (self.fields[f].options[:localize] rescue false) + field_name = "#{f}_translations" + end + ruling_timer_history.send("#{field_name}=",self.send(field_name)) + end + ruling_timer_history.date = self.get_last_work_time.new_offset(self.time_offset).strftime("%Y/%m/%d %w") + ruling_timer_history.user = self.user + ruling_timer_history.save + end + available_locales = I18n.available_locales + not_reset_fields = ["time_offset","user_id","tasks_finished","sub_task_ids","tasks"] + fields.each do |f| + next if not_reset_fields.include?(f) + default_value = self.fields[f].options[:default] rescue nil + if (self.fields[f].options[:localize] rescue false) + field_name = "#{f}_translations" + self.send("#{f}_translations=",available_locales.map{|l| [l.to_s,default_value]}.to_h) + else + self.send("#{f}=",default_value) + end + end + if self.tasks_finished.count != 0 + temp_task_ids = self.sub_task_ids.clone + temp_tasks = self.tasks.clone + temp_tasks_finished = self.tasks_finished.clone.sort.reverse + temp_tasks_finished.each do |idx| + temp_task_ids.delete_at(idx) + temp_tasks.delete_at(idx) + end + self.sub_task_ids = temp_task_ids + self.tasks = temp_tasks + self.tasks_finished = [] + end + time_now = DateTime.now.utc + self.created_at = time_now + self.updated_at = time_now + self.date = time_now.new_offset(self.time_offset).strftime("%Y/%m/%d %w") + self.save + end +end \ No newline at end of file diff --git a/app/views/.keep b/app/views/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/admin/ruling_timers/_task_form.html.erb b/app/views/admin/ruling_timers/_task_form.html.erb new file mode 100644 index 0000000..8414b61 --- /dev/null +++ b/app/views/admin/ruling_timers/_task_form.html.erb @@ -0,0 +1,31 @@ +
+ +
+ <%= f.text_field :task_name %> +
+
+
+ +
+
+ <%= @selected_users.join("\n").html_safe %> +
+
+ +
+
+ +
+ <% referer = request.referer rescue nil %> + <% referer = get_referer_url if referer.blank? || request.host != URI.parse(URI.encode(referer)).host %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), referer, :class=>"btn" %> +
+ \ No newline at end of file diff --git a/app/views/admin/ruling_timers/_timer_work_row.html.erb b/app/views/admin/ruling_timers/_timer_work_row.html.erb new file mode 100644 index 0000000..867da69 --- /dev/null +++ b/app/views/admin/ruling_timers/_timer_work_row.html.erb @@ -0,0 +1,23 @@ + + <%= timer.date.split(" ")[0] + " " + @weekdays[timer.date.split(" ")[1].to_i] %> + <%= timer.summary.to_s.gsub("\n","
").html_safe %> + + <% work_times = timer.get_work_times %> + <% work_times.each_with_index do |t,i| %> + <% if i % 2 == 0 + next_t = work_times[i+1] + else + next + end %> + <%= "#{t} ~ #{next_t.nil? ? "Now" : next_t}" %> +
+ <% end %> + <%= I18n.t("ruling_timer.total") %>: <%= timer.get_infos["work"] %> + + + <%=t("edit")%> + <% if params[:id].nil? || params[:id] == current_user.id.to_s%> + <%=t("delete_")%> + <% end %> + + \ No newline at end of file diff --git a/app/views/admin/ruling_timers/_user_card.html.erb b/app/views/admin/ruling_timers/_user_card.html.erb new file mode 100644 index 0000000..fabe4ec --- /dev/null +++ b/app/views/admin/ruling_timers/_user_card.html.erb @@ -0,0 +1,8 @@ +<% checked = false if defined?(checked).nil? %> +
  • + + <%= check_box_tag "#{@user_params_name}", (user.id rescue nil) , (checked ? true : false) , :id => "user_ids_#{(user.id rescue '')}"%> +
  • \ No newline at end of file diff --git a/app/views/admin/ruling_timers/_user_select_modal.html.erb b/app/views/admin/ruling_timers/_user_select_modal.html.erb new file mode 100644 index 0000000..6fbab17 --- /dev/null +++ b/app/views/admin/ruling_timers/_user_select_modal.html.erb @@ -0,0 +1,61 @@ +<%= stylesheet_link_tag "member_select" %> +<%= stylesheet_link_tag "lib/checkbox-card" %> + + + \ No newline at end of file diff --git a/app/views/admin/ruling_timers/add_history.html.erb b/app/views/admin/ruling_timers/add_history.html.erb new file mode 100644 index 0000000..6067ac3 --- /dev/null +++ b/app/views/admin/ruling_timers/add_history.html.erb @@ -0,0 +1,78 @@ + +

    <%=@user.name%>

    +<%= form_for @history, url: create_history_admin_ruling_timers_path(@history), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= f.hidden_field :user_id%> + <%= f.hidden_field :time_offset, :id=>"history_timeoffset" %> +
    + +
    + <%= f.datetime_picker :date, {:picker_type=>"date",:no_label=>true,:format=>"yyyy/MM/dd"} %> +
    +
    +
    + +
    + <%= f.text_area :summary,:id=>"edit_summary" %> +
    +
    +
    + +
    + <% work_times = @history.get_work_times(true) %> + <% work_times.each_with_index do |t,i| %> + <% if i % 2 == 0 + next_t = work_times[i+1] + else + next + end %> + <%= f.text_field_tag "#{f.object_name}[work_times][]", t ,:id=>nil %> ~ <%= f.text_field_tag "#{f.object_name}[work_times][]", next_t ,:id=>nil %> +
    + <% end %> +
    + +
    +
    + +
    + <% referer = request.referer rescue nil %> + <% referer = get_referer_url if referer.blank? || request.host != URI.parse(URI.encode(referer)).host %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), referer, :class=>"btn" %> +
    +
    + +<% end %> \ No newline at end of file diff --git a/app/views/admin/ruling_timers/add_task.html.erb b/app/views/admin/ruling_timers/add_task.html.erb new file mode 100644 index 0000000..78941f9 --- /dev/null +++ b/app/views/admin/ruling_timers/add_task.html.erb @@ -0,0 +1,6 @@ +<%= render :partial => "user_select_modal",:locals=>{:@users=>@users,:@selected_user_ids=>@task.user_ids,:@target=>"#user_append_area",:@user_params_name=>"#{@task.class.to_s.underscore}[user_ids][]"} %> +<%= form_for @task, url: create_task_admin_ruling_timers_path(@task), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render :partial => "task_form",:locals=>{:f=>f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/ruling_timers/edit_task.html.erb b/app/views/admin/ruling_timers/edit_task.html.erb new file mode 100644 index 0000000..afd3198 --- /dev/null +++ b/app/views/admin/ruling_timers/edit_task.html.erb @@ -0,0 +1,6 @@ +<%= render :partial => "user_select_modal",:locals=>{:@users=>@users,:@selected_user_ids=>@task.user_ids,:@target=>"#user_append_area",:@user_params_name=>"#{@task.class.to_s.underscore}[user_ids][]"} %> +<%= form_for @task, url: update_task_admin_ruling_timer_path(@task), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    + <%= render :partial => "task_form",:locals=>{:f=>f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/ruling_timers/edit_timer.html.erb b/app/views/admin/ruling_timers/edit_timer.html.erb new file mode 100644 index 0000000..ed44208 --- /dev/null +++ b/app/views/admin/ruling_timers/edit_timer.html.erb @@ -0,0 +1,68 @@ + +<%= form_for @timer, url: update_timer_admin_ruling_timer_path(@timer), html: {class: "form-horizontal main-forms previewable"} do |f| %> +
    +

    <%= @timer.date.split(" ")[0] + " " + @weekdays[@timer.date.split(" ")[1].to_i] %>

    + <% if @timer.class == RulingTimerTemp %> + + <% end %> +
    + +
    + <%= f.text_area :summary,:id=>"edit_summary" %> +
    +
    +
    + +
    + <% work_times = @timer.get_work_times(true) %> + <% work_times.each_with_index do |t,i| %> + <% if i % 2 == 0 + next_t = work_times[i+1] + else + next + end %> + <%= f.text_field_tag "#{f.object_name}[work_times][]", t ,:id=>nil %> ~ <%= f.text_field_tag "#{f.object_name}[work_times][]", next_t ,:id=>nil %> +
    + <% end %> +
    + +
    +
    + +
    + <% referer = request.referer rescue nil %> + <% referer = get_referer_url if referer.blank? || request.host != URI.parse(URI.encode(referer)).host %> + <%= f.submit t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), referer, :class=>"btn" %> +
    +
    + +<% end %> \ No newline at end of file diff --git a/app/views/admin/ruling_timers/index.html.erb b/app/views/admin/ruling_timers/index.html.erb new file mode 100644 index 0000000..fc62564 --- /dev/null +++ b/app/views/admin/ruling_timers/index.html.erb @@ -0,0 +1,85 @@ +

    + <% if @user_name %> + <%=t("ruling_timer.user_work_history",{:user=>@user_name})%> + <% else %> + <%=t("ruling_timer.my_work_history")%> + <% end %> +

    + + + + + + + + + + + <% if @ruling_timer_temp %> + <%= render :partial => "timer_work_row", :locals=>{:timer=>@ruling_timer_temp} %> + <% end %> + <% @ruling_timer_history.each do |timer_history| %> + <%= render :partial => "timer_work_row", :locals=>{:timer=>timer_history} %> + <% end %> + +
    <%=t("ruling_timer.date")%><%=t("ruling_timer.summary")%><%=t("ruling_timer.work_time")%><%=t("action")%>
    +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag(:div, paginate(@ruling_pager), class: "pagination pagination-centered") + + link_to(t("ruling_timer.add_history"),add_history_admin_ruling_timer_path(:id=>(params[:id].nil? ? "current_user" : params[:id])),:class=>"btn btn-primary pull-right") + end +%> + \ No newline at end of file diff --git a/app/views/admin/ruling_timers/task_management.html.erb b/app/views/admin/ruling_timers/task_management.html.erb new file mode 100644 index 0000000..0ac00bc --- /dev/null +++ b/app/views/admin/ruling_timers/task_management.html.erb @@ -0,0 +1,130 @@ + +

    <%= t("ruling_timer.task") %>

    + + + + + + + + + + <% @tasks.each_with_index do |task,i| %> + + + + + + <% end %> + +
    <%= t("ruling_timer.task_name") %><%= t("ruling_timer.task_performer") %><%=t("action")%>
    <%=task.task_name%> + <% 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') %> + <%=user.name%>( <%=sub_task.get_infos["work"] rescue "00:00:00" %> ) +
    + <% end %> + <% end %> +
    + <%=t("view")%> + <%=t("edit")%> + <%=t("ruling_timer.delete_task")%> +
    +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag(:div, paginate(@tasks), class: "pagination pagination-centered") + + content_tag(:div, link_to(t("ruling_timer.add_task"), add_task_admin_ruling_timers_path, :class=>"btn btn-primary"), class: "pull-right") + end %> + \ No newline at end of file diff --git a/app/views/admin/ruling_timers/timer_management.html.erb b/app/views/admin/ruling_timers/timer_management.html.erb new file mode 100644 index 0000000..daf563c --- /dev/null +++ b/app/views/admin/ruling_timers/timer_management.html.erb @@ -0,0 +1,47 @@ + +

    <%= t("ruling_timer.member") %>

    +<% timer_temps = @timer_temps.to_a%> +<% @active_users.each_with_index do |user,i| %> +
    + <% name = user.name %> + <% link = work_history_admin_ruling_timer_path(:id=>user.id) %> + +
    + <% timer_temp = timer_temps[i] %> + <% if timer_temp.status != "stop" %> + <%=t("ruling_timer.#{timer_temp.status}")%> + <% else %> + <%=t("ruling_timer.offline")%> + <% end %> +
    + <%=name%> +
    + <%= '
    '.html_safe if (i % 5 == 4) %> +<% end %> +<%= paginate(@timer_temps)%> \ No newline at end of file diff --git a/app/views/admin/ruling_timers/view_task.html.erb b/app/views/admin/ruling_timers/view_task.html.erb new file mode 100644 index 0000000..752fe29 --- /dev/null +++ b/app/views/admin/ruling_timers/view_task.html.erb @@ -0,0 +1,66 @@ + +
    +

    <%= @task.task_name%>

    +
    + + + + + + + + + <% 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') %> + + + + +
    + <% end %> + <% end %> + +
    <%= t("ruling_timer.task_performer") %><%= t("ruling_timer.task_execution_time") %>
    <%=user.name%> + <% 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}" %> +
    + <% end %> +
    + <%=t("ruling_timer.#{sub_task.status}")%>( <%=t("ruling_timer.total")%>: <%=sub_task.get_infos["work"] rescue "00:00:00" %> ) +
    +
    +
    +<%= + 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('ruling_timer.back'), referer, :class=>"btn") + end %> + \ No newline at end of file diff --git a/app/views/ruling_timers/_timer_button.html.erb b/app/views/ruling_timers/_timer_button.html.erb new file mode 100644 index 0000000..e8cbe67 --- /dev/null +++ b/app/views/ruling_timers/_timer_button.html.erb @@ -0,0 +1,302 @@ +<% if current_user %> + <%= csrf_meta_tags %> + <% @ruling_timer_temp = RulingTimerTemp.where(:user=>current_user).first %> + <% @ruling_timer_temp = RulingTimerTemp.new if @ruling_timer_temp.nil? %> + <% @ruling_timer_temp.check_and_store %> + <% @new_sub_tasks = RulingTimerSubTask.where(:user=>current_user,:status.ne=>"finish",:id.nin=>@ruling_timer_temp.sub_task_ids).to_a %> +
    +
    + + + <%=DateTime.now.new_offset('+08:00').strftime('%l:%M %p')%> + + + + <% if @ruling_timer_temp.status == "working" %> + + <%=t("ruling_timer.working")%> + <% else %> + + + <% if @ruling_timer_temp.status == "rest"%> + 繼續 + <% else %> + <% if @ruling_timer_temp.all_work_times_seconds == 0 %> + 打卡上班 + <% else %> + 記錄的下班時間 + <% end %> + <% end %> + + <% end %> + + + <% if @new_sub_tasks.count != 0 %> + + <% end %> + +
    +
    + + +<% end %> \ No newline at end of file diff --git a/app/views/ruling_timers/_timer_window.html.erb b/app/views/ruling_timers/_timer_window.html.erb new file mode 100644 index 0000000..777146d --- /dev/null +++ b/app/views/ruling_timers/_timer_window.html.erb @@ -0,0 +1,793 @@ +<% if (current_user rescue false)%> + <% @ruling_timer_temp.reset_all %> + <% @timer_infos = @ruling_timer_temp.get_infos %> + + + + + + +<% end %> \ No newline at end of file diff --git a/bin/rails b/bin/rails new file mode 100644 index 0000000..8144d80 --- /dev/null +++ b/bin/rails @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +# This command will automatically be run when you run "rails" with Rails gems +# installed from the root of your application. + +ENGINE_ROOT = File.expand_path('..', __dir__) +ENGINE_PATH = File.expand_path('../lib/sync_ntnu_personal_data/engine', __dir__) +APP_PATH = File.expand_path('../test/dummy/config/application', __dir__) + +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) + +require 'rails/all' +require 'rails/engine/commands' diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..bcc5f4b --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,55 @@ +en: + restful_actions: + task_management: Task Management + timer_management: Timer Management + work_history: Work history + edit_temp_timer: Edit history + edit_temp_timer: Edit history + add_task: Add task + edit_task: Edit task + add_history: "Add history" + module_name: + ruling_timer: Ruling timer + ruling_timer: + please_input_larger_than_value: "Please input larger than {{value}}!" + please_input_smaller_than_value: "Please input smaller than {{value}}!" + view_history: "View history" + add_history: "Add history" + task_execution_time: "Task execution time" + back: Back + cancel: Cancel + confirm: Confirm + confirm_delete: "Confirm delete" + please_input_confirm_delete: "Please input 'Confirm delete' to here." + delete_history_hint1: "Do you really want to delete this history({{history}})?" + delete_history_hint: "Do you really want to delete this history?" + delete_task_hint1: "Do you really want to delete this task({{task}})?" + delete_task_hint: "Do you really want to delete this task?" + new_tasks_hint: "New tasks can be added!" + add_member: Add Member + delete_task: "Delete task" + add_task: Add task + task: Task + task_performer: Task performer + task_name: Task name + finish: Finish + stop: Stop + working: Working + rest: Rest + offline: Offline + member: Member + total: Total + ruling_timer: Ruling timer + user_work_history: "%{user}'s Work History" + my_work_history: My Work History + summary: Summary + date: Date + work_time: Work time + week_days: + sunday: Sunday + monday: Monday + tuesday: Tuesday + wednesday: Wednesday + thursday: Thursday + friday: Friday + saturday: Saturday \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml new file mode 100644 index 0000000..39d40e8 --- /dev/null +++ b/config/locales/zh_tw.yml @@ -0,0 +1,55 @@ +zh_tw: + restful_actions: + task_management: 任務管理 + timer_management: 計時管理 + work_history: 工作紀錄 + edit_temp_timer: 編輯紀錄 + edit_timer: 編輯紀錄 + add_task: 新增任務 + edit_task: 編輯任務 + add_history: 新增紀錄 + module_name: + ruling_timer: 計時器模組 + ruling_timer: + please_input_larger_than_value: "請輸入大於{{value}}的值!" + please_input_smaller_than_value: "請輸入小於{{value}}的值!" + view_history: 查看歷史紀錄 + add_history: 新增紀錄 + task_execution_time: "任務執行時間" + back: 回上一頁 + cancel: 取消 + confirm: 確認 + confirm_delete: "確認刪除" + please_input_confirm_delete: "請輸入'確認刪除'。" + delete_history_hint1: "您真的想刪除此任務({{history}})嗎?" + delete_history_hint: "您真的想刪除此紀錄嗎?" + delete_task_hint1: "您真的想刪除此任務({{task}})嗎?" + delete_task_hint: "您真的想刪除此任務嗎?" + new_tasks_hint: 有新的任務可添加 + add_member: 添加成員 + delete_task: 刪除任務 + add_task: 新增任務 + task: 任務 + task_performer: 任務執行者 + task_name: 任務名稱 + finish: 已完成 + stop: 暫停 + working: 工作中 + rest: 休息中 + offline: 離線 + member: 成員 + total: 共計 + ruling_timer: 計時器模組 + user_work_history: "%{user}的工作紀錄" + my_work_history: 我的工作紀錄 + summary: 摘要 + date: 日期 + work_time: 工作時間 + week_days: + sunday: 週日 + monday: 週一 + tuesday: 週二 + wednesday: 週三 + thursday: 週四 + friday: 週五 + saturday: 週六 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..15d6c70 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,55 @@ +Rails.application.routes.draw do + locales = Site.first.in_use_locales rescue I18n.available_locales + s = Site.first + save_flag = false + if !s.orbit_bar_extra_render_files_inside.include?("ruling_timers/timer_button") + s.orbit_bar_extra_render_files_inside << "ruling_timers/timer_button" + save_flag = true + end + if !s.orbit_bar_extra_render_files_outside.include?("ruling_timers/timer_window") + s.orbit_bar_extra_render_files_outside << "ruling_timers/timer_window" + save_flag = true + end + s.save if save_flag + namespace :admin do + resources :ruling_timers do + member do + post "delete_history" + get "add_history" + get "work_history" + get "edit_timer" + get "edit_temp_timer" + patch "update_timer" + patch "update_task" + get "edit_task" + post "delete_task" + get "view_task" + end + collection do + post "create_history" + patch "create_history" + get "timer_management" + get "task_management" + get "add_task" + post "create_task" + patch "create_task" + end + end + end + scope "(:locale)", locale: Regexp.new(locales.join("|")) do + post "/xhr/ruling_timer/start" => "ruling_timers#start" + post "/xhr/ruling_timer/stop" => "ruling_timers#stop" + post "/xhr/ruling_timer/rest" => "ruling_timers#rest" + post "/xhr/ruling_timer/set_summary" => "ruling_timers#set_summary" + post "/xhr/ruling_timer/add_task" => "ruling_timers#add_task" + post "/xhr/ruling_timer/add_task_from_list" => "ruling_timers#add_task_from_list" + post "/xhr/ruling_timer/remove_task" => "ruling_timers#remove_task" + post "/xhr/ruling_timer/set_task_status" => "ruling_timers#set_task_status" + post "/xhr/ruling_timer/start_task" => "ruling_timers#start_task" + post "/xhr/ruling_timer/stop_task" => "ruling_timers#stop_task" + post "/xhr/ruling_timer/add_event" => "ruling_timers#add_event" + post "/xhr/ruling_timer/delete_event" => "ruling_timers#delete_event" + post "/xhr/ruling_timer/get_work_times" => "ruling_timers#get_work_times" + post "/xhr/ruling_timer/save_work_times" => "ruling_timers#save_work_times" + end +end \ No newline at end of file diff --git a/lib/ruling_timer.rb b/lib/ruling_timer.rb new file mode 100644 index 0000000..1a3fed0 --- /dev/null +++ b/lib/ruling_timer.rb @@ -0,0 +1,5 @@ +require "ruling_timer/engine" + +module RulingTimer + # Your code goes here... +end diff --git a/lib/ruling_timer/engine.rb b/lib/ruling_timer/engine.rb new file mode 100644 index 0000000..6f5d2a7 --- /dev/null +++ b/lib/ruling_timer/engine.rb @@ -0,0 +1,30 @@ +module RulingTimer + class Engine < ::Rails::Engine + initializer "ruling_timer" do + OrbitApp.registration "RulingTimer", :type => "ModuleApp" do + module_label "ruling_timer.ruling_timer" + base_url File.expand_path File.dirname(__FILE__) + authorizable + + side_bar do + head_label_i18n 'ruling_timer.ruling_timer', icon_class: "icons-clock" + available_for "users" + active_for_controllers (['admin/seminars']) + head_link_path "admin_ruling_timers_path" + + context_link 'restful_actions.timer_management', + :link_path=>"timer_management_admin_ruling_timers_path" , + :priority=>1, + :active_for_action=>{'admin/ruling_timers'=>'timer_management'}, + :available_for => 'managers' + context_link 'restful_actions.task_management', + :link_path=>"task_management_admin_ruling_timers_path" , + :priority=>2, + :active_for_action=>{'admin/ruling_timers'=>'task_management'}, + :available_for => 'managers' + end + + end + end + end +end diff --git a/lib/ruling_timer/version.rb b/lib/ruling_timer/version.rb new file mode 100644 index 0000000..cbac893 --- /dev/null +++ b/lib/ruling_timer/version.rb @@ -0,0 +1,3 @@ +module RulingTimer + VERSION = '0.0.1' +end diff --git a/ruling_timer.gemspec b/ruling_timer.gemspec new file mode 100644 index 0000000..fec5492 --- /dev/null +++ b/ruling_timer.gemspec @@ -0,0 +1,27 @@ +$:.push File.expand_path("lib", __dir__) + +# Maintain your gem's version: +require "ruling_timer/version" +# Describe your gem and declare its dependencies: +Gem::Specification.new do |spec| + spec.name = "ruling_timer" + spec.version = RulingTimer::VERSION + spec.authors = ["Bohung Chiu"] + spec.email = ["bohung@rulingcom.com"] + spec.homepage = "https://w3.rulingcom.com/" + spec.summary = "Ruling Timer for users" + spec.description = "Ruling Timer for users" + spec.license = "MIT" + + # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' + # to allow pushing to a single host or delete this section to allow pushing to any host. + if spec.respond_to?(:metadata) + spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" + else + raise "RubyGems 2.0 or newer is required to protect against " \ + "public gem pushes." + end + + spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] + +end diff --git a/test/dummy/.ruby-version b/test/dummy/.ruby-version new file mode 100644 index 0000000..fe16b34 --- /dev/null +++ b/test/dummy/.ruby-version @@ -0,0 +1 @@ +2.5.4 diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile new file mode 100644 index 0000000..e85f913 --- /dev/null +++ b/test/dummy/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative 'config/application' + +Rails.application.load_tasks diff --git a/test/dummy/app/assets/config/manifest.js b/test/dummy/app/assets/config/manifest.js new file mode 100644 index 0000000..5918193 --- /dev/null +++ b/test/dummy/app/assets/config/manifest.js @@ -0,0 +1,2 @@ +//= link_tree ../images +//= link_directory ../stylesheets .css diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..0ebd7fe --- /dev/null +++ b/test/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/test/dummy/app/channels/application_cable/channel.rb b/test/dummy/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/test/dummy/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/test/dummy/app/channels/application_cable/connection.rb b/test/dummy/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/test/dummy/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/test/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/dummy/app/javascript/packs/application.js b/test/dummy/app/javascript/packs/application.js new file mode 100644 index 0000000..67ce467 --- /dev/null +++ b/test/dummy/app/javascript/packs/application.js @@ -0,0 +1,15 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. JavaScript code in this file should be added after the last require_* statement. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require rails-ujs +//= require activestorage +//= require_tree . diff --git a/test/dummy/app/jobs/application_job.rb b/test/dummy/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/test/dummy/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/test/dummy/app/mailers/application_mailer.rb b/test/dummy/app/mailers/application_mailer.rb new file mode 100644 index 0000000..286b223 --- /dev/null +++ b/test/dummy/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: 'from@example.com' + layout 'mailer' +end diff --git a/test/dummy/app/models/application_record.rb b/test/dummy/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/test/dummy/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..24307d3 --- /dev/null +++ b/test/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= stylesheet_link_tag 'application', media: 'all' %> + + + + <%= yield %> + + diff --git a/test/dummy/app/views/layouts/mailer.html.erb b/test/dummy/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..cbd34d2 --- /dev/null +++ b/test/dummy/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/test/dummy/app/views/layouts/mailer.text.erb b/test/dummy/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/test/dummy/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails new file mode 100644 index 0000000..0739660 --- /dev/null +++ b/test/dummy/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake new file mode 100644 index 0000000..1724048 --- /dev/null +++ b/test/dummy/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/test/dummy/bin/setup b/test/dummy/bin/setup new file mode 100644 index 0000000..0e39e8c --- /dev/null +++ b/test/dummy/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require 'fileutils' + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + # puts "\n== Copying sample files ==" + # unless File.exist?('config/database.yml') + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:prepare' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/test/dummy/config.ru b/test/dummy/config.ru new file mode 100644 index 0000000..f7ba0b5 --- /dev/null +++ b/test/dummy/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb new file mode 100644 index 0000000..860ebbd --- /dev/null +++ b/test/dummy/config/application.rb @@ -0,0 +1,19 @@ +require_relative 'boot' + +require 'rails/all' + +Bundler.require(*Rails.groups) +require "sync_ntnu_personal_data" + +module Dummy + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.0 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + end +end + diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb new file mode 100644 index 0000000..c9aef85 --- /dev/null +++ b/test/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) diff --git a/test/dummy/config/cable.yml b/test/dummy/config/cable.yml new file mode 100644 index 0000000..98367f8 --- /dev/null +++ b/test/dummy/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: dummy_production diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml new file mode 100644 index 0000000..4a8a1b2 --- /dev/null +++ b/test/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb new file mode 100644 index 0000000..426333b --- /dev/null +++ b/test/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb new file mode 100644 index 0000000..7e49c00 --- /dev/null +++ b/test/dummy/config/environments/development.rb @@ -0,0 +1,62 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb new file mode 100644 index 0000000..b7ad81b --- /dev/null +++ b/test/dummy/config/environments/production.rb @@ -0,0 +1,112 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "dummy_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session +end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb new file mode 100644 index 0000000..de83a77 --- /dev/null +++ b/test/dummy/config/environments/test.rb @@ -0,0 +1,48 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.cache_classes = false + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true +end diff --git a/test/dummy/config/initializers/application_controller_renderer.rb b/test/dummy/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..89d2efa --- /dev/null +++ b/test/dummy/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/test/dummy/config/initializers/assets.rb b/test/dummy/config/initializers/assets.rb new file mode 100644 index 0000000..fe48fc3 --- /dev/null +++ b/test/dummy/config/initializers/assets.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in the app/assets +# folder are already added. +# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/test/dummy/config/initializers/content_security_policy.rb b/test/dummy/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..41c4301 --- /dev/null +++ b/test/dummy/config/initializers/content_security_policy.rb @@ -0,0 +1,28 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy +# For further information see the following documentation +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy + +# Rails.application.config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https + +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end + +# If you are using UJS then enable automatic nonce generation +# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } + +# Set the nonce only to specific directives +# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) + +# Report CSP violations to a specified URI +# For further information see the following documentation: +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only +# Rails.application.config.content_security_policy_report_only = true diff --git a/test/dummy/config/initializers/cookies_serializer.rb b/test/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..5a6a32d --- /dev/null +++ b/test/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Specify a serializer for the signed and encrypted cookie jars. +# Valid options are :json, :marshal, and :hybrid. +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/test/dummy/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/test/dummy/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..bbfc396 --- /dev/null +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml new file mode 100644 index 0000000..cf9b342 --- /dev/null +++ b/test/dummy/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/test/dummy/config/puma.rb b/test/dummy/config/puma.rb new file mode 100644 index 0000000..5ed4437 --- /dev/null +++ b/test/dummy/config/puma.rb @@ -0,0 +1,38 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb new file mode 100644 index 0000000..c06383a --- /dev/null +++ b/test/dummy/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html +end diff --git a/test/dummy/config/spring.rb b/test/dummy/config/spring.rb new file mode 100644 index 0000000..db5bf13 --- /dev/null +++ b/test/dummy/config/spring.rb @@ -0,0 +1,6 @@ +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/test/dummy/config/storage.yml b/test/dummy/config/storage.yml new file mode 100644 index 0000000..d32f76e --- /dev/null +++ b/test/dummy/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/log/.keep b/test/dummy/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html new file mode 100644 index 0000000..2be3af2 --- /dev/null +++ b/test/dummy/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
    +
    +

    The page you were looking for doesn't exist.

    +

    You may have mistyped the address or the page may have moved.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/422.html b/test/dummy/public/422.html new file mode 100644 index 0000000..c08eac0 --- /dev/null +++ b/test/dummy/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
    +
    +

    The change you wanted was rejected.

    +

    Maybe you tried to change something you didn't have access to.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/500.html b/test/dummy/public/500.html new file mode 100644 index 0000000..78a030a --- /dev/null +++ b/test/dummy/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
    +
    +

    We're sorry, but something went wrong.

    +
    +

    If you are the application owner check the logs for more information.

    +
    + + diff --git a/test/dummy/public/apple-touch-icon-precomposed.png b/test/dummy/public/apple-touch-icon-precomposed.png new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/public/apple-touch-icon.png b/test/dummy/public/apple-touch-icon.png new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/public/favicon.ico b/test/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/navigation_test.rb b/test/integration/navigation_test.rb new file mode 100644 index 0000000..29e59d8 --- /dev/null +++ b/test/integration/navigation_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class NavigationTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/ruling_timer_test.rb b/test/ruling_timer_test.rb new file mode 100644 index 0000000..7a1d4af --- /dev/null +++ b/test/ruling_timer_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class RulingTimer::Test < ActiveSupport::TestCase + test "truth" do + assert_kind_of Module, RulingTimer + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..d2af136 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,18 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require_relative "../test/dummy/config/environment" +ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] +require "rails/test_help" + +# Filter out the backtrace from minitest while preserving the one from other libraries. +Minitest.backtrace_filter = Minitest::BacktraceFilter.new + + +# Load fixtures from the engine +if ActiveSupport::TestCase.respond_to?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__) + ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path + ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files" + ActiveSupport::TestCase.fixtures :all +end