Skip to content

Commit

Permalink
add stimulus controller
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Dec 3, 2024
1 parent 0de222f commit 5b70f7e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
44 changes: 44 additions & 0 deletions frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* -- copyright
* OpenProject is an open source project management software.
* Copyright (C) the OpenProject GmbH
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3.
*
* OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
* Copyright (C) 2006-2013 Jean-Philippe Lang
* Copyright (C) 2010-2013 the ChiliProject Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* See COPYRIGHT and LICENSE files for more details.
* ++
*/

import { Controller } from '@hotwired/stimulus';

export default class TimeEntryController extends Controller {
static targets = ['startTimeInput', 'endTimeInput', 'hoursInput'];

declare readonly startTimeInputTarget:HTMLInputElement;
declare readonly endTimeInputTarget:HTMLInputElement;
declare readonly choursInputTarget:HTMLInputElement;

startTimeInputTargetConnected() {
// console.log('We have a start input');
this.startTimeInputTarget.value = '12:00';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render(Primer::Alpha::Dialog.new(title: 'Log Time', size: :large, id: MODAL_ID)) do |d| %>
<%= render(Primer::Alpha::Dialog.new(title: 'Log Time', size: :large, id: MODAL_ID, data: { "controller" => "time-entry", "application-target" => "dynamic" })) do |d| %>
<% d.with_header(variant: :large, mb: 3) %>
<%= render(TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry)) %>
<% end %>
4 changes: 3 additions & 1 deletion modules/costs/app/components/time_entries/time_entry_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class TimeEntryForm < ApplicationForm
end
f.text_field name: :spent_on, label: "Date"
f.group(layout: :horizontal) do |g|
g.text_field name: :start_time, label: "Start time"
g.text_field name: :start_time,
label: "Start time",
data: { "time-entry-target" => "startTimeInput" }
g.text_field name: :end_time, label: "Finish time"
end
f.text_field name: :hours, label: "Hours"
Expand Down

0 comments on commit 5b70f7e

Please sign in to comment.