diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 027f1a1..695b7fd 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -288,3 +288,11 @@ span#password { font-weight: normal; margin-bottom: 5px; } + +summary { + font-size: 12px; +} + +summary:hover { + cursor: pointer; +} diff --git a/app/controllers/instance_controller.rb b/app/controllers/instance_controller.rb index abc1d21..737abba 100644 --- a/app/controllers/instance_controller.rb +++ b/app/controllers/instance_controller.rb @@ -80,6 +80,20 @@ class InstanceController < ApplicationController end end + def adjust_pop + instance_id, nm, pwd = pop_instance_params + parent_instance = Instance.find_by(public_id: instance_id) + if params[:mins] && params[:pwd] == parent_instance.password + ts = Time.now.utc + pop = Pop.find_by(instance_id: parent_instance.id, name: nm) + pop.created_at = Time.at(ts - params[:mins].to_i.minutes).utc + pop.save + @instance = Instance.includes(:pops, :fairies).find_by(public_id: instance_id) + @forecast = Weather.forecast(@instance.zone.to_sym) + render partial: "list", locals: { instance: @instance, forecast: @forecast } + end + end + def reset instance_id, nm, pwd = pop_instance_params parent_instance = Instance.find_by(public_id: instance_id) diff --git a/app/javascript/list.js b/app/javascript/list.js index fc8d3a8..9b6bea8 100644 --- a/app/javascript/list.js +++ b/app/javascript/list.js @@ -19,6 +19,12 @@ function checkPwd() { btn.setAttribute("hx-post", `${oldUrl}&pwd=${pwd}`); }); + const forms = document.querySelectorAll(".action-form"); + forms.forEach(form => { + const oldUrl = form.getAttribute("action"); + form.setAttribute("action", `${oldUrl}&pwd=${pwd}`); + }); + const pwd_el = document.getElementById("password"); pwd_el.innerHTML = pwd; } diff --git a/app/views/instance/_list.html.erb b/app/views/instance/_list.html.erb index 03e2db9..cf45a33 100644 --- a/app/views/instance/_list.html.erb +++ b/app/views/instance/_list.html.erb @@ -36,6 +36,14 @@ +
+ adjust pop time + <%= form_with url: adjust_pop_path(instance: instance.public_id, nm: nm[:name].parameterize), class: "action-form", html: {"hx-boost": true, "hx-replace-url": false, "hx-target": "#nm-list", "hx-select": "#nm-list", "hx-swap": "outerHTML:w +"} do |f| %> + <%= f.number_field :mins, placeholder: "minutes ago" %> + <%= f.submit "change" %> + <% end %> +
<% else %> <% if nm[:weather] && forecast[0][:curr_weather] != nm[:weather] %> <% next_pattern = forecast.find { |f| f[:curr_weather] == nm[:weather] } %> diff --git a/config/routes.rb b/config/routes.rb index ec9c047..bc88fe6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Rails.application.routes.draw do post "/new", to: "instance#create", as: :new_instance post "/new_from_fe", to: "instance#create_from_fe", as: :new_from_fe post "/pop", to: "instance#pop", as: :pop_in_instance + post "/pop/adjust", to: "instance#adjust_pop", as: :adjust_pop post "/reset", to: "instance#reset", as: :reset_in_instance post "/auth", to: "instance#authenticate", as: :authenticate_to_instance post "/fairy/mark", to: "fairy#mark", as: :mark_fairy