decidim-time_tracker 0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE-AGPLv3.txt +661 -0
- data/README.md +174 -0
- data/Rakefile +40 -0
- data/app/assets/config/admin/decidim_time_tracker_manifest.css +2 -0
- data/app/assets/config/admin/decidim_time_tracker_manifest.js +1 -0
- data/app/assets/config/decidim_time_tracker_manifest.css +3 -0
- data/app/assets/config/decidim_time_tracker_manifest.js +1 -0
- data/app/assets/images/decidim/time_tracker/icon.svg +1 -0
- data/app/assets/javascripts/decidim/time_tracker/activity_ui.js.es6 +112 -0
- data/app/assets/javascripts/decidim/time_tracker/admin/assignations.js.es6 +35 -0
- data/app/assets/javascripts/decidim/time_tracker/reports/reports.js.es6 +19 -0
- data/app/assets/javascripts/decidim/time_tracker/time_tracker.js.es6 +82 -0
- data/app/assets/javascripts/decidim/time_tracker/timer_api.js.es6 +55 -0
- data/app/assets/stylesheets/decidim/time_tracker/_variables.scss +1 -0
- data/app/assets/stylesheets/decidim/time_tracker/admin/time_tracker.scss +59 -0
- data/app/assets/stylesheets/decidim/time_tracker/time_tracker.scss +118 -0
- data/app/cells/decidim/time_tracker/milestone/show.erb +42 -0
- data/app/cells/decidim/time_tracker/milestone_cell.rb +54 -0
- data/app/commands/decidim/time_tracker/admin/create_activity.rb +39 -0
- data/app/commands/decidim/time_tracker/admin/create_assignation.rb +75 -0
- data/app/commands/decidim/time_tracker/admin/create_task.rb +33 -0
- data/app/commands/decidim/time_tracker/admin/create_time_tracker.rb +76 -0
- data/app/commands/decidim/time_tracker/admin/destroy_activity.rb +43 -0
- data/app/commands/decidim/time_tracker/admin/destroy_assignation.rb +43 -0
- data/app/commands/decidim/time_tracker/admin/destroy_task.rb +43 -0
- data/app/commands/decidim/time_tracker/admin/export_time_tracker.rb +150 -0
- data/app/commands/decidim/time_tracker/admin/update_activity.rb +49 -0
- data/app/commands/decidim/time_tracker/admin/update_assignation.rb +42 -0
- data/app/commands/decidim/time_tracker/admin/update_task.rb +44 -0
- data/app/commands/decidim/time_tracker/create_milestone.rb +57 -0
- data/app/commands/decidim/time_tracker/create_request_assignation.rb +39 -0
- data/app/commands/decidim/time_tracker/start_time_event.rb +104 -0
- data/app/commands/decidim/time_tracker/stop_last_time_event.rb +45 -0
- data/app/controllers/concerns/decidim/time_tracker/admin/filterable_assignations.rb +50 -0
- data/app/controllers/decidim/time_tracker/activity_questionnaire_controller.rb +76 -0
- data/app/controllers/decidim/time_tracker/admin/activities_controller.rb +82 -0
- data/app/controllers/decidim/time_tracker/admin/activity_questionnaire_controller.rb +52 -0
- data/app/controllers/decidim/time_tracker/admin/application_controller.rb +22 -0
- data/app/controllers/decidim/time_tracker/admin/assignations_controller.rb +84 -0
- data/app/controllers/decidim/time_tracker/admin/assignee_questionnaire_controller.rb +58 -0
- data/app/controllers/decidim/time_tracker/admin/stats_controller.rb +24 -0
- data/app/controllers/decidim/time_tracker/admin/tasks_controller.rb +112 -0
- data/app/controllers/decidim/time_tracker/admin/time_tracker_exports_controller.rb +25 -0
- data/app/controllers/decidim/time_tracker/application_controller.rb +24 -0
- data/app/controllers/decidim/time_tracker/assignations_controller.rb +38 -0
- data/app/controllers/decidim/time_tracker/assignee_questionnaire_controller.rb +80 -0
- data/app/controllers/decidim/time_tracker/milestones_controller.rb +62 -0
- data/app/controllers/decidim/time_tracker/reports/user_controller.rb +38 -0
- data/app/controllers/decidim/time_tracker/time_events_controller.rb +68 -0
- data/app/controllers/decidim/time_tracker/time_tracker_controller.rb +43 -0
- data/app/forms/decidim/time_tracker/admin/activity_form.rb +27 -0
- data/app/forms/decidim/time_tracker/admin/assignation_form.rb +29 -0
- data/app/forms/decidim/time_tracker/admin/task_form.rb +22 -0
- data/app/forms/decidim/time_tracker/milestone_form.rb +32 -0
- data/app/forms/decidim/time_tracker/time_event_form.rb +47 -0
- data/app/helpers/decidim/time_tracker/admin/application_helper.rb +33 -0
- data/app/helpers/decidim/time_tracker/application_helper.rb +95 -0
- data/app/jobs/decidim/time_tracker/stop_counter_job.rb +29 -0
- data/app/models/decidim/time_tracker/activity.rb +135 -0
- data/app/models/decidim/time_tracker/application_record.rb +10 -0
- data/app/models/decidim/time_tracker/assignation.rb +68 -0
- data/app/models/decidim/time_tracker/assignee.rb +29 -0
- data/app/models/decidim/time_tracker/assignee_data.rb +19 -0
- data/app/models/decidim/time_tracker/milestone.rb +27 -0
- data/app/models/decidim/time_tracker/task.rb +44 -0
- data/app/models/decidim/time_tracker/time_event.rb +62 -0
- data/app/models/decidim/time_tracker/time_tracker.rb +46 -0
- data/app/models/decidim/time_tracker/tos_acceptance.rb +16 -0
- data/app/permissions/decidim/time_tracker/admin/permissions.rb +69 -0
- data/app/permissions/decidim/time_tracker/permissions.rb +69 -0
- data/app/presenters/decidim/time_tracker/admin_log/activity_presenter.rb +44 -0
- data/app/presenters/decidim/time_tracker/admin_log/assignation_presenter.rb +48 -0
- data/app/presenters/decidim/time_tracker/admin_log/task_presenter.rb +46 -0
- data/app/presenters/decidim/time_tracker/admin_log/value_types/activity_presenter.rb +28 -0
- data/app/presenters/decidim/time_tracker/admin_log/value_types/time_tracker_presenter.rb +28 -0
- data/app/views/decidim/time_tracker/admin/_breadcrumbs.html.erb +56 -0
- data/app/views/decidim/time_tracker/admin/activities/_form.html.erb +41 -0
- data/app/views/decidim/time_tracker/admin/activities/_index.html.erb +73 -0
- data/app/views/decidim/time_tracker/admin/activities/edit.html.erb +5 -0
- data/app/views/decidim/time_tracker/admin/activities/new.html.erb +5 -0
- data/app/views/decidim/time_tracker/admin/assignations/_form.html.erb +30 -0
- data/app/views/decidim/time_tracker/admin/assignations/index.html.erb +67 -0
- data/app/views/decidim/time_tracker/admin/assignations/new.html.erb +9 -0
- data/app/views/decidim/time_tracker/admin/questionnaires/_index.html.erb +27 -0
- data/app/views/decidim/time_tracker/admin/questionnaires/_questionnaire.html.erb +21 -0
- data/app/views/decidim/time_tracker/admin/stats/index.html.erb +50 -0
- data/app/views/decidim/time_tracker/admin/tasks/_assignations.html.erb +60 -0
- data/app/views/decidim/time_tracker/admin/tasks/_form.html.erb +7 -0
- data/app/views/decidim/time_tracker/admin/tasks/_index.html.erb +61 -0
- data/app/views/decidim/time_tracker/admin/tasks/edit.html.erb +16 -0
- data/app/views/decidim/time_tracker/admin/tasks/index.html.erb +5 -0
- data/app/views/decidim/time_tracker/admin/tasks/new.html.erb +12 -0
- data/app/views/decidim/time_tracker/milestones/index.html.erb +60 -0
- data/app/views/decidim/time_tracker/reports/user/index.html.erb +41 -0
- data/app/views/decidim/time_tracker/time_tracker/_activity.html.erb +43 -0
- data/app/views/decidim/time_tracker/time_tracker/_answer_questionnaire.html.erb +7 -0
- data/app/views/decidim/time_tracker/time_tracker/_assignee_data.html.erb +9 -0
- data/app/views/decidim/time_tracker/time_tracker/_callout_status.html.erb +3 -0
- data/app/views/decidim/time_tracker/time_tracker/_idle_activity.html.erb +27 -0
- data/app/views/decidim/time_tracker/time_tracker/_milestone_form.html.erb +35 -0
- data/app/views/decidim/time_tracker/time_tracker/_request_activity.html.erb +22 -0
- data/app/views/decidim/time_tracker/time_tracker/_sign_in.html.erb +5 -0
- data/app/views/decidim/time_tracker/time_tracker/index.html.erb +59 -0
- data/config/activity_questionnaire.yml +26 -0
- data/config/assignee_questionnaire.yml +37 -0
- data/config/i18n-tasks.yml +10 -0
- data/config/locales/ca.yml +394 -0
- data/config/locales/cs.yml +394 -0
- data/config/locales/en.yml +419 -0
- data/config/locales/es.yml +394 -0
- data/db/migrate/20200302115642_create_decidim_time_tracker_time_trackers.rb +10 -0
- data/db/migrate/20200302115654_create_decidim_time_tracker_tasks.rb +11 -0
- data/db/migrate/20200302115658_create_decidim_time_tracker_assignees.rb +12 -0
- data/db/migrate/20200302115700_create_decidim_time_tracker_activities.rb +19 -0
- data/db/migrate/20200302115708_create_decidim_time_tracker_milestones.rb +13 -0
- data/db/migrate/20200302115831_create_decidim_time_tracker_assignations.rb +16 -0
- data/db/migrate/20200302115840_create_decidim_time_tracker_time_events.rb +15 -0
- data/db/migrate/20201118153327_create_decidim_time_tracker_assignee_data.rb +10 -0
- data/db/migrate/20201223115130_create_decidim_time_tracker_tos_acceptances.rb +18 -0
- data/lib/decidim/time_tracker.rb +45 -0
- data/lib/decidim/time_tracker/admin.rb +10 -0
- data/lib/decidim/time_tracker/admin_engine.rb +51 -0
- data/lib/decidim/time_tracker/component.rb +248 -0
- data/lib/decidim/time_tracker/engine.rb +59 -0
- data/lib/decidim/time_tracker/reports.rb +10 -0
- data/lib/decidim/time_tracker/reports_engine.rb +34 -0
- data/lib/decidim/time_tracker/test/admin_log_presenter_examples.rb +34 -0
- data/lib/decidim/time_tracker/test/factories.rb +110 -0
- data/lib/decidim/time_tracker/test/time_tracker_context.rb +18 -0
- data/lib/decidim/time_tracker/time_tracker_activity_questionnaire_answers_serializer.rb +74 -0
- data/lib/decidim/time_tracker/version.rb +9 -0
- data/vendor/assets/javascripts/jsrender.min.js +4 -0
- metadata +276 -0
data/README.md
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# Decidim::TimeTracker
|
2
|
+
|
3
|
+
[![Test](https://github.com/Platoniq/decidim-module-time_tracker/workflows/Test/badge.svg)](https://github.com/Platoniq/decidim-module-time_tracker/actions)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/9372a7def91c50d04e8c/maintainability)](https://codeclimate.com/github/Platoniq/decidim-module-time_tracker/maintainability)
|
5
|
+
[![codecov](https://codecov.io/gh/Platoniq/decidim-module-time_tracker/branch/master/graph/badge.svg)](https://codecov.io/gh/Platoniq/decidim-module-time_tracker)
|
6
|
+
|
7
|
+
> **WARNING** This is not ready for production usage yet (though soon will be).
|
8
|
+
|
9
|
+
A tool for Decidim that allows to track time dedicated by volunteers doing any arbitrary task.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
TimeTracker will be available as a Component for a Participatory
|
14
|
+
Space.
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem "decidim-time_tracker", git: "https://github.com/Platoniq/decidim-module-time_tracker"
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
bundle
|
28
|
+
bundle exec rails decidim_time_tracker:install:migrations
|
29
|
+
bundle exec rails db:migrate
|
30
|
+
```
|
31
|
+
|
32
|
+
## About Time tracker and attached questionnaires
|
33
|
+
|
34
|
+
By default, every time tracker component has an attached questionnaire for the volunteer to fill with their personal data and to give their consent to the T&C (further referenced as **questionnaire for assignees**). Activities have also an attached questionnaire for the volunteer to fill when they request to be assigned to that activity (further referenced as **questionnaire for activities**). This is a very simple questionnaire with questions about how certain tasks may usually be perceived as related to certain genders. This can be useful to have a better understanding of the perception of tasks and their real gender assignation.
|
35
|
+
|
36
|
+
Both questionnaires are enabled by default and can be customized. You may also disable the questionnaire shown for activities. However, take into account that administrators can always modify or create custom questionnaires.
|
37
|
+
|
38
|
+
If you want to customize the default questionnaires or disable the questionnaire for activities, just create a new initializer in `config/initializers/time_tracker.rb` with the following content:
|
39
|
+
|
40
|
+
**To use your own questionnaire for _assignees_** (use [config/default_assignee_questionnaire.yml](config/default_assignee_questionnaire.yml) as an example guide):
|
41
|
+
```ruby
|
42
|
+
# config/initializers/time_tracker.rb
|
43
|
+
|
44
|
+
# Initialize my custom questionnaire placed in config/my_questionnaire.yml
|
45
|
+
Decidim::TimeTracker.configure do |config|
|
46
|
+
config.default_assignee_questionnaire_seeds = YAML.load_file File.join(Rails.root, 'config', 'my_assignee_questionnaire.yml')
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
**To use your own questionnaire for _activities_** (use [config/default_activity_questionnaire.yml](config/default_activity_questionnaire.yml) as an example guide):
|
51
|
+
```ruby
|
52
|
+
# config/initializers/time_tracker.rb
|
53
|
+
|
54
|
+
# Initialize my custom questionnaire placed in config/my_questionnaire.yml
|
55
|
+
Decidim::TimeTracker.configure do |config|
|
56
|
+
config.default_activity_questionnaire_seeds = YAML.load_file File.join(Rails.root, 'config', 'my_activities_questionnaire.yml')
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
**To completely disable the default questionnaire for _activities_**:
|
61
|
+
```ruby
|
62
|
+
# config/initializers/time_tracker.rb
|
63
|
+
|
64
|
+
# Disable the default questionnaire for time tracker
|
65
|
+
Decidim::TimeTracker.configure do |config|
|
66
|
+
config.default_activity_questionnaire_seeds = nil
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
> **NOTE:** If you customize your questionnaires, you can use any I18n key to translate it. Just add it to your locales.
|
71
|
+
> You also can just put a direct text with no translations, then it will be used for all languages.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
See [Decidim](https://github.com/decidim/decidim).
|
76
|
+
|
77
|
+
### Developing
|
78
|
+
|
79
|
+
To start contributing to this project, first:
|
80
|
+
|
81
|
+
- Install the basic dependencies (such as Ruby and PostgreSQL)
|
82
|
+
- Clone this repository
|
83
|
+
|
84
|
+
Decidim's main repository also provides a Docker configuration file if you
|
85
|
+
prefer to use Docker instead of installing the dependencies locally on your
|
86
|
+
machine.
|
87
|
+
|
88
|
+
You can create the development app by running the following commands after
|
89
|
+
cloning this project:
|
90
|
+
|
91
|
+
```bash
|
92
|
+
bundle
|
93
|
+
DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake development_app
|
94
|
+
```
|
95
|
+
|
96
|
+
Note that the database user has to have rights to create and drop a database in
|
97
|
+
order to create the dummy test app database.
|
98
|
+
|
99
|
+
Then to test how the module works in Decidim, start the development server:
|
100
|
+
|
101
|
+
```bash
|
102
|
+
cd development_app
|
103
|
+
DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rails s
|
104
|
+
```
|
105
|
+
|
106
|
+
In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
|
107
|
+
[rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
|
108
|
+
can add the environment variables to the root directory of the project in a file
|
109
|
+
named `.rbenv-vars`. If these are defined for the environment, you can omit
|
110
|
+
defining these in the commands shown above.
|
111
|
+
|
112
|
+
#### Code Styling
|
113
|
+
|
114
|
+
Please follow the code styling defined by the different linters that ensure we
|
115
|
+
are all talking with the same language collaborating on the same project. This
|
116
|
+
project is set to follow the same rules that Decidim itself follows.
|
117
|
+
|
118
|
+
[Rubocop](https://rubocop.readthedocs.io/) linter is used for the Ruby language.
|
119
|
+
|
120
|
+
You can run the code styling checks by running the following commands from the
|
121
|
+
console:
|
122
|
+
|
123
|
+
```
|
124
|
+
bundle exec rubocop
|
125
|
+
```
|
126
|
+
|
127
|
+
To ease up following the style guide, you should install the plugin to your
|
128
|
+
favorite editor, such as:
|
129
|
+
|
130
|
+
- Atom - [linter-rubocop](https://atom.io/packages/linter-rubocop)
|
131
|
+
- Sublime Text - [Sublime RuboCop](https://github.com/pderichs/sublime_rubocop)
|
132
|
+
- Visual Studio Code - [Rubocop for Visual Studio Code](https://github.com/misogi/vscode-ruby-rubocop)
|
133
|
+
|
134
|
+
### Testing
|
135
|
+
|
136
|
+
To run the tests run the following in the gem development path:
|
137
|
+
|
138
|
+
```bash
|
139
|
+
bundle
|
140
|
+
DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rake test_app
|
141
|
+
DATABASE_USERNAME=<username> DATABASE_PASSWORD=<password> bundle exec rspec
|
142
|
+
```
|
143
|
+
|
144
|
+
Note that the database user has to have rights to create and drop a database in
|
145
|
+
order to create the dummy test app database.
|
146
|
+
|
147
|
+
In case you are using [rbenv](https://github.com/rbenv/rbenv) and have the
|
148
|
+
[rbenv-vars](https://github.com/rbenv/rbenv-vars) plugin installed for it, you
|
149
|
+
can add these environment variables to the root directory of the project in a
|
150
|
+
file named `.rbenv-vars`. In this case, you can omit defining these in the
|
151
|
+
commands shown above.
|
152
|
+
|
153
|
+
### Test code coverage
|
154
|
+
|
155
|
+
If you want to generate the code coverage report for the tests, you can use
|
156
|
+
the `SIMPLECOV=1` environment variable in the rspec command as follows:
|
157
|
+
|
158
|
+
```bash
|
159
|
+
SIMPLECOV=1 bundle exec rspec
|
160
|
+
```
|
161
|
+
|
162
|
+
This will generate a folder named `coverage` in the project root which contains
|
163
|
+
the code coverage report.
|
164
|
+
|
165
|
+
### Localization
|
166
|
+
|
167
|
+
If you would like to see this module in your own language, you can help with its
|
168
|
+
translation at Crowdin:
|
169
|
+
|
170
|
+
https://crowdin.com/project/decidim-module-time_tracker
|
171
|
+
|
172
|
+
## License
|
173
|
+
|
174
|
+
This engine is distributed under the GNU AFFERO GENERAL PUBLIC LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "decidim/dev/common_rake"
|
4
|
+
|
5
|
+
def install_module(path)
|
6
|
+
Dir.chdir(path) do
|
7
|
+
system("bundle exec rake decidim_time_tracker:install:migrations")
|
8
|
+
system("bundle exec rake db:migrate")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def seed_db(path)
|
13
|
+
Dir.chdir(path) do
|
14
|
+
system("bundle exec rake db:seed")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Generates a dummy app for testing"
|
19
|
+
task test_app: "decidim:generate_external_test_app" do
|
20
|
+
ENV["RAILS_ENV"] = "test"
|
21
|
+
install_module("spec/decidim_dummy_app")
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Generates a development app."
|
25
|
+
task :development_app do
|
26
|
+
Bundler.with_original_env do
|
27
|
+
generate_decidim_app(
|
28
|
+
"development_app",
|
29
|
+
"--app_name",
|
30
|
+
"#{base_app_name}_development_app",
|
31
|
+
"--path",
|
32
|
+
"..",
|
33
|
+
"--recreate_db",
|
34
|
+
"--demo"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
install_module("development_app")
|
39
|
+
seed_db("development_app")
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link decidim/time_tracker/admin/assignations.js
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link decidim/time_tracker/time_tracker.js
|
@@ -0,0 +1 @@
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 35 35"><path d="M17.5 35A17.5 17.5 0 1 1 35 17.5 17.52 17.52 0 0 1 17.5 35zm0-33.06A15.56 15.56 0 1 0 33.06 17.5 15.57 15.57 0 0 0 17.5 1.94zm9.5 13.7H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zm0 3.68H8a1 1 0 0 1 0-1.94h19a1 1 0 0 1 0 1.94zM22.26 23H8a1 1 0 0 1 0-1.94h14.26a1 1 0 0 1 0 1.94z"/></svg>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
class ActivityUI { // eslint-disable-line no-unused-vars
|
2
|
+
constructor(target) {
|
3
|
+
this.$activity = $(target);
|
4
|
+
this.$elapsed = this.$activity.find(".elapsed-time-clock");
|
5
|
+
this.$startButton = this.$activity.find(".time-tracker-activity-start");
|
6
|
+
this.$pauseButton = this.$activity.find(".time-tracker-activity-pause");
|
7
|
+
this.$stopButton = this.$activity.find(".time-tracker-activity-stop");
|
8
|
+
this.interval = null;
|
9
|
+
this.initTime = this.now;
|
10
|
+
this.onStop = $.noop;
|
11
|
+
}
|
12
|
+
|
13
|
+
get startEndpoint() {
|
14
|
+
return this.$activity.data('start-endpoint');
|
15
|
+
}
|
16
|
+
|
17
|
+
get stopEndpoint() {
|
18
|
+
return this.$activity.data('stop-endpoint');
|
19
|
+
}
|
20
|
+
|
21
|
+
get now() {
|
22
|
+
return Math.floor(new Date().getTime() / 1000);
|
23
|
+
}
|
24
|
+
|
25
|
+
get elapsed() {
|
26
|
+
return parseInt(this.$activity.data("elapsed-time") || 0, 10);
|
27
|
+
}
|
28
|
+
|
29
|
+
set elapsed(seconds) {
|
30
|
+
this.$activity.data("elapsed-time", seconds);
|
31
|
+
}
|
32
|
+
|
33
|
+
get remaining() {
|
34
|
+
return parseInt(this.$activity.data("remaining-time") || 0, 10);
|
35
|
+
}
|
36
|
+
|
37
|
+
set remaining(seconds) {
|
38
|
+
this.$activity.data("remaining-time", seconds);
|
39
|
+
}
|
40
|
+
|
41
|
+
showStart() {
|
42
|
+
this.$startButton.removeClass("hide");
|
43
|
+
this.$pauseButton.addClass("hide");
|
44
|
+
this.$stopButton.addClass("hide");
|
45
|
+
return this;
|
46
|
+
}
|
47
|
+
|
48
|
+
showPauseStop() {
|
49
|
+
this.$startButton.addClass("hide");
|
50
|
+
this.$pauseButton.removeClass("hide");
|
51
|
+
this.$stopButton.removeClass("hide");
|
52
|
+
return this;
|
53
|
+
}
|
54
|
+
|
55
|
+
showPlayStop() {
|
56
|
+
this.$startButton.removeClass("hide");
|
57
|
+
this.$pauseButton.addClass("hide");
|
58
|
+
this.$stopButton.removeClass("hide");
|
59
|
+
return this;
|
60
|
+
}
|
61
|
+
|
62
|
+
showError(error) {
|
63
|
+
this.$activity.find(".callout.alert").html(error).removeClass("hide");
|
64
|
+
this.showStart(this.$activity);
|
65
|
+
return this;
|
66
|
+
}
|
67
|
+
|
68
|
+
clockifySeconds(totalSeconds) {
|
69
|
+
const hours = Math.floor(totalSeconds / (60 * 60))
|
70
|
+
const minutes = Math.floor((totalSeconds / 60) % 60)
|
71
|
+
const seconds = totalSeconds % 60
|
72
|
+
|
73
|
+
return `${ hours }h ${ minutes }m ${ seconds }s`
|
74
|
+
}
|
75
|
+
|
76
|
+
updateElapsedTime() {
|
77
|
+
const diff = this.now - this.initTime
|
78
|
+
if(this.remaining <= diff) {
|
79
|
+
this.stopCounter()
|
80
|
+
return this.onStop();
|
81
|
+
}
|
82
|
+
this.$elapsed.html(this.clockifySeconds(this.elapsed + diff));
|
83
|
+
}
|
84
|
+
|
85
|
+
startCounter(data) {
|
86
|
+
console.log("starting counter", data)
|
87
|
+
clearInterval(this.interval);
|
88
|
+
this.initTime = this.now;
|
89
|
+
this.interval = setInterval(() => {
|
90
|
+
this.updateElapsedTime();
|
91
|
+
}, 1000);
|
92
|
+
return this;
|
93
|
+
}
|
94
|
+
|
95
|
+
stopCounter(data) {
|
96
|
+
const diff = this.now - this.initTime
|
97
|
+
console.log("stopping counter", data)
|
98
|
+
this.elapsed = this.elapsed + diff;
|
99
|
+
this.remaining = this.remaining - diff;
|
100
|
+
clearInterval(this.interval);
|
101
|
+
return this;
|
102
|
+
}
|
103
|
+
|
104
|
+
isRunning() {
|
105
|
+
return !!this.interval;
|
106
|
+
}
|
107
|
+
|
108
|
+
showMilestone() {
|
109
|
+
console.log("TODO: show milestone")
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
((exports) => {
|
2
|
+
const { createFieldDependentInputs } = exports.DecidimAdmin;
|
3
|
+
|
4
|
+
const $assignationType = $("#assignation_existing_user");
|
5
|
+
|
6
|
+
createFieldDependentInputs({
|
7
|
+
controllerField: $assignationType,
|
8
|
+
wrapperSelector: ".user-fields",
|
9
|
+
dependentFieldsSelector: ".user-fields--email",
|
10
|
+
dependentInputSelector: "input",
|
11
|
+
enablingCondition: ($field) => {
|
12
|
+
return $field.val() === "false"
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
createFieldDependentInputs({
|
17
|
+
controllerField: $assignationType,
|
18
|
+
wrapperSelector: ".user-fields",
|
19
|
+
dependentFieldsSelector: ".user-fields--name",
|
20
|
+
dependentInputSelector: "input",
|
21
|
+
enablingCondition: ($field) => {
|
22
|
+
return $field.val() === "false"
|
23
|
+
}
|
24
|
+
});
|
25
|
+
|
26
|
+
createFieldDependentInputs({
|
27
|
+
controllerField: $assignationType,
|
28
|
+
wrapperSelector: ".user-fields",
|
29
|
+
dependentFieldsSelector: ".user-fields--user-picker",
|
30
|
+
dependentInputSelector: "input",
|
31
|
+
enablingCondition: ($field) => {
|
32
|
+
return $field.val() === "true"
|
33
|
+
}
|
34
|
+
});
|
35
|
+
})(window);
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$(() => {
|
2
|
+
$(document).ready(( ) => {
|
3
|
+
const params = new URLSearchParams(window.location.search);
|
4
|
+
const activity_id = params.get('activity');
|
5
|
+
|
6
|
+
if (activity_id) {
|
7
|
+
const $activity = $(`[data-activity-id=${activity_id}]`);
|
8
|
+
|
9
|
+
if ($activity.length) {
|
10
|
+
$("body,html").animate({
|
11
|
+
scrollTop: ($activity.offset().top - $activity.height() / 2)
|
12
|
+
},
|
13
|
+
200
|
14
|
+
);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
19
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
//= require decidim/time_tracker/timer_api
|
2
|
+
//= require decidim/time_tracker/activity_ui
|
3
|
+
//= require decidim/time_tracker/reports/reports
|
4
|
+
//= require jsrender.min
|
5
|
+
//= require_self
|
6
|
+
|
7
|
+
$(() => {
|
8
|
+
|
9
|
+
// For each request track ajax responses
|
10
|
+
$(document).on("ajax:success", ".time-tracker-request", (event) => {
|
11
|
+
const detail = event.detail;
|
12
|
+
const data = detail[0];
|
13
|
+
$(event.target).replaceWith(`<div class="callout success">${data.message}</div>`);
|
14
|
+
})
|
15
|
+
$(document).on("ajax:error", ".time-tracker-request", (event) => {
|
16
|
+
const detail = event.detail;
|
17
|
+
const data = detail[0];
|
18
|
+
const $form = $(event.target);
|
19
|
+
const $callout = $(`<div class="callout alert">${data.message}</div>`).insertAfter($form);
|
20
|
+
$form.hide();
|
21
|
+
setTimeout(() => $callout.fadeOut(() => {$callout.remove(); $form.show();}), 2000);
|
22
|
+
});
|
23
|
+
|
24
|
+
// For each activty set up the counters
|
25
|
+
$(".time-tracker-activity").each(function() {
|
26
|
+
const $activity = $(this);
|
27
|
+
const $milestone = $activity.find(".milestone");
|
28
|
+
const activity = new ActivityUI($activity);
|
29
|
+
const api = new TimerApi(activity.startEndpoint, activity.stopEndpoint);
|
30
|
+
// store api
|
31
|
+
$activity.data('_activity', activity);
|
32
|
+
$activity.data('_api', api);
|
33
|
+
if($activity.data("counter-active")) {
|
34
|
+
activity.showPauseStop();
|
35
|
+
activity.startCounter();
|
36
|
+
}
|
37
|
+
|
38
|
+
activity.onStop = () => {
|
39
|
+
console.log("automatic stop");
|
40
|
+
activity.showError($activity.data("text-counter-stopped"));
|
41
|
+
activity.showStart();
|
42
|
+
api.stop(); // Unnecessary if the job is working well
|
43
|
+
};
|
44
|
+
|
45
|
+
$activity.find(".time-tracker-activity-start").on("click", () => {
|
46
|
+
activity.showPauseStop();
|
47
|
+
api.start()
|
48
|
+
.done((data) => {
|
49
|
+
// stop others
|
50
|
+
$(".time-tracker-activity").each(function() {
|
51
|
+
const activity = $(this).data("_activity");
|
52
|
+
if(activity.isRunning()) {
|
53
|
+
activity.showPlayStop().stopCounter();
|
54
|
+
}
|
55
|
+
});
|
56
|
+
activity.startCounter(data)
|
57
|
+
})
|
58
|
+
.fail(activity.showError.bind(activity));
|
59
|
+
});
|
60
|
+
|
61
|
+
|
62
|
+
$activity.find(".time-tracker-activity-pause").on("click", () => {
|
63
|
+
activity.showPlayStop();
|
64
|
+
api.stop()
|
65
|
+
.done((data) => activity.stopCounter(data))
|
66
|
+
.fail(activity.showError.bind(activity));
|
67
|
+
});
|
68
|
+
|
69
|
+
$activity.find(".time-tracker-activity-stop").on("click", () => {
|
70
|
+
activity.showStart();
|
71
|
+
api.stop()
|
72
|
+
.done((data) => {
|
73
|
+
activity.stopCounter(data);
|
74
|
+
console.log("show milestone creator");
|
75
|
+
$milestone.removeClass("hide");
|
76
|
+
})
|
77
|
+
.fail(activity.showError.bind(activity));
|
78
|
+
});
|
79
|
+
});
|
80
|
+
|
81
|
+
});
|
82
|
+
|