diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 705b1a97..5c3fb862 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,17 +3,14 @@ - - - - - - + + + - + @@ -28,7 +25,7 @@ - + @@ -55,41 +52,51 @@ - + - - + + - - + + - - + + - + - - + + - - + + - - + + + + + + + + + + + + @@ -98,42 +105,23 @@ - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + + - - + + - - + + @@ -173,10 +161,6 @@ @@ -756,12 +744,12 @@ - + - @@ -774,7 +762,6 @@ - @@ -784,9 +771,9 @@ - + - + @@ -804,51 +791,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1088,7 +1035,7 @@ - + @@ -1106,7 +1053,7 @@ - + @@ -1151,18 +1098,18 @@ - + - - + + - + - - + + @@ -1179,42 +1126,87 @@ - + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index 6ac04659..ff76d3b1 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -1,5 +1,5 @@ class Origami::InJutiesController < BaseOrigamiController - before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] + before_action :set_in_juty, only: %i[show edit update edit_in_juty update_for_in_juty destroy destroy_in_juty] # GET /in_juties # GET /in_juties.json @@ -8,11 +8,12 @@ class Origami::InJutiesController < BaseOrigamiController end def index_in_juty - @juty_in= InJuty.where("dinning_id=?",params[:table_id]) + @juty_in = InJuty.where('dinning_id=?', params[:table_id]) @table = DiningFacility.find(params[:table_id]) - @in_juty = InJuty.new + @in_juty = InJuty.new @juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10) end + # GET /in_juties/1 # GET /in_juties/1.json def show @@ -20,12 +21,15 @@ class Origami::InJutiesController < BaseOrigamiController # GET /in_juties/new def new + # this one use for new @in_juty = InJuty.new + @table = DiningFacility.find(params[:table_id]) + @commissioner = @in_juty.commissioner + render partial: 'form' end # GET /in_juties/1/edit def edit - end def edit_in_juty @@ -33,13 +37,15 @@ class Origami::InJutiesController < BaseOrigamiController @table = DiningFacility.find(params[:table_id]) @commissioner = @in_juty.commissioner - render json: {in_juty: @in_juty, commissioner: @commissioner} + # render json: {in_juty: @in_juty, commissioner: @commissioner} + render partial: 'form' end def assign_in_juty @in_juty = InJuty.new @table = DiningFacility.find(params[:table_id]) end + # POST /in_juties # POST /in_juties.json def create @@ -57,32 +63,53 @@ class Origami::InJutiesController < BaseOrigamiController end def create_for_in_juty + # this one use for create and update + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') @in_juty = InJuty.new + in_juty_id = in_juty[:id] + unless in_juty_id.nil? + @in_juty = InJuty.find(in_juty_id.to_i) + end @in_juty.dinning_id = in_juty_params[:dinning_id] @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] - @in_juty.in_time = in_juty_params[:in_time] - @in_juty.out_time = in_juty_params[:out_time] - + @in_juty.in_time = in_time + @in_juty.out_time = out_time respond_to do |format| if @in_juty.save - format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' } - format.json { render :show, status: :created, location: @in_juty } + if in_juty_id.nil? + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' } + format.json { render :show, status: :created, location: @in_juty } + else + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } + format.json { render :show, status: :created, location: @in_juty } + end else format.html { render :new } format.json { render json: @in_juty.errors, status: :unprocessable_entity } end end - end # PATCH/PUT /in_juties/1 # PATCH/PUT /in_juties/1.json def update + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_time + @in_juty.out_time = out_time respond_to do |format| - if @in_juty.update(in_juty_params) - format.html { redirect_to origami_in_juty_path(@in_juty), notice: 'In juty was successfully updated.' } + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } format.json { render :show, status: :ok, location: @in_juty } else format.html { render :edit } @@ -91,28 +118,32 @@ class Origami::InJutiesController < BaseOrigamiController end end - - def update_for_in_juty - @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] - @in_juty.in_time = in_juty_params[:in_time] - @in_juty.out_time = in_juty_params[:out_time] - respond_to do |format| - if @in_juty.save - format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } - format.json { render :show, status: :ok, location: @in_juty } - else - format.html { render :edit } - format.json { render json: @in_juty.errors, status: :unprocessable_entity } - end - end + def update_for_in_juty + in_juty = in_juty_params + in_time = DateTime.new in_juty['in_time(1i)'].to_i, in_juty['in_time(2i)'].to_i, in_juty['in_time(3i)'].to_i, in_juty['in_time(4i)'].to_i, in_juty['in_time(5i)'].to_i + in_time = in_time.change(offset: '+06:30') + out_time = DateTime.new in_juty['out_time(1i)'].to_i, in_juty['out_time(2i)'].to_i, in_juty['out_time(3i)'].to_i, in_juty['out_time(4i)'].to_i, in_juty['out_time(5i)'].to_i + out_time = out_time.change(offset: '+06:30') + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_time + @in_juty.out_time = out_time + respond_to do |format| + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } + format.json { render :show, status: :ok, location: @in_juty } + else + format.html { render :edit } + format.json { render json: @in_juty.errors, status: :unprocessable_entity } + end end + end # DELETE /in_juties/1 # DELETE /in_juties/1.json def destroy @in_juty.destroy respond_to do |format| - format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully removed.' } format.json { head :no_content } end end @@ -122,19 +153,20 @@ class Origami::InJutiesController < BaseOrigamiController @in_juty.destroy respond_to do |format| - format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully removed.' } format.json { head :no_content } end end private - # Use callbacks to share common setup or constraints between actions. - def set_in_juty - @in_juty = InJuty.find(params[:id]) - end - # Never trust parameters from the scary internet, only allow the white list through. - def in_juty_params - params.require(:in_juty).permit(:id,:dinning_id,:commissioner_ids,:in_time,:out_time) - end + # Use callbacks to share common setup or constraints between actions. + def set_in_juty + @in_juty = InJuty.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def in_juty_params + params.require(:in_juty).permit(:id, :dinning_id, :commissioner_ids, :in_time, :out_time) + end end diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 62531529..b6363195 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -18,7 +18,7 @@ <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %> - <%= f.input :out_time, :placeholder => "From Date", :class => "form-control" %> + <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %>
diff --git a/app/views/origami/in_juties/_edit_in_juty.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb index 9eaf8353..a297ac65 100644 --- a/app/views/origami/in_juties/_edit_in_juty.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -1,13 +1,14 @@ -<%= simple_form_for([:origami,@in_juty]) do |f| %> - <%= f.error_notification %> +<%= simple_form_for([:origami, @in_juty]) do |f| %> + <%= f.error_notification %> -
- <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>

- <%= f.input :in_time %> - <%= f.input :out_time %> -
+
+ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %> +

+ <%= f.input :in_time %> + <%= f.input :out_time %> +
-
- <%= f.button :submit %> -
-<% end %> \ No newline at end of file +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/origami/in_juties/_form.html.erb b/app/views/origami/in_juties/_form.html.erb index d67df51b..9bed9152 100644 --- a/app/views/origami/in_juties/_form.html.erb +++ b/app/views/origami/in_juties/_form.html.erb @@ -1,33 +1,43 @@ -
-<%= simple_form_for([:origami,@in_juty]) do |f| %> - <%= f.error_notification %> +<%= simple_form_for @in_juty, :url => origami_index_in_juty_path(@table.id), :method => :post do |f| %> + + <%= f.error_notification %> + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + +
+ + <%= f.hidden_field :dinning_id, :value => @table.id, :class => "form-control col-md-4 " %> + + + <%= @table.name %> +
+
+ + + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %> +

+ + <%= f.input :in_time, :placeholder => "From Date", :class => "form-control" %> + + <%= f.input :out_time, :placeholder => "To Date", :class => "form-control" %> + +

+ +
+ <% f.button :submit, "Create", :class => 'btn btn-primary ', :id => 'create' %> + <% f.button :submit, "Update", :class => 'btn btn-primary ', :disabled => '', :id => 'update' %> + <% f.button :button, "Reset", :class => 'btn btn-danger ', :id => 'reset' %> +
+
+ <%= f.button :submit, :class => 'btn btn-primary' %> +
-
- <%= f.label :dinning_id %> - <%= f.collection_select :dinning_id, DiningFacility.all, :id, :name, {prompt: 'Select Dining Facilities'}, {class: 'form-control'} %>
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
- - <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
- - <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%> -

-
- <%= link_to 'Back', origami_in_juties_path, class: 'btn btn-success' %> - <%= f.button :submit, class: 'btn btn-info' %> -
<% end %> -
+ \ No newline at end of file + }); + + diff --git a/app/views/origami/in_juties/index.html.erb b/app/views/origami/in_juties/index.html.erb index 6efeb999..ff5a0fd3 100644 --- a/app/views/origami/in_juties/index.html.erb +++ b/app/views/origami/in_juties/index.html.erb @@ -1,38 +1,91 @@ - -
-
- - - - - - - - - - - - - <% @in_juties.each do |in_juty| %> - - - - - - - - - - <% end %> - -
Dining Facility NameCommissioner IdsIn timeOut time
<%= in_juty.dining_facility.name rescue '-' %><%= in_juty.commissioner.name rescue '-' %><%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= link_to 'Show', origami_in_juty_path(in_juty) %><%= link_to 'Edit', edit_origami_in_juty_path(in_juty) %><%= link_to 'Destroy', origami_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %>
+
+
+ + + diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index bbb9912b..52d79c89 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -22,7 +22,7 @@ <%= in_juty.commissioner.name rescue '-' %> <%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> <%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> - <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> + <%= link_to 'Remove', origami_destroy_in_juty_path(in_juty.dining_facility.id, in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> <% end %> @@ -30,13 +30,14 @@ <%= paginate @juties_in %>
-
- <%= render 'assign_in_juty', in_juty: @in_juty, table: @table %> +
+ <%= render 'form', in_juty: @in_juty, table: @table %>
-
- +
+      +
diff --git a/app/views/origami/in_juties/new.html.erb b/app/views/origami/in_juties/new.html.erb index eb34f01c..f59ff6fd 100644 --- a/app/views/origami/in_juties/new.html.erb +++ b/app/views/origami/in_juties/new.html.erb @@ -6,5 +6,5 @@
  • New
  • - <%= render 'form', in_juty: @in_juty %> + <%= render 'form', in_juty: @in_juty, table: @table %> diff --git a/dump.rdb b/dump.rdb index 332310c7..c5350a13 100644 Binary files a/dump.rdb and b/dump.rdb differ