diff --git a/app/assets/stylesheets/content/_custom_actions.sass b/app/assets/stylesheets/content/_custom_actions.sass
index e83db9aaa3..c10e26c2c3 100644
--- a/app/assets/stylesheets/content/_custom_actions.sass
+++ b/app/assets/stylesheets/content/_custom_actions.sass
@@ -46,3 +46,6 @@
width: 100%
// The margin is necessary for all buttons so that the alignment is correct on small screens
margin-right: 10px
+
+wp-custom-actions-admin-date-action
+ display: flex
diff --git a/app/contracts/work_packages/update_contract.rb b/app/contracts/work_packages/update_contract.rb
index a03101466f..357e58ec1d 100644
--- a/app/contracts/work_packages/update_contract.rb
+++ b/app/contracts/work_packages/update_contract.rb
@@ -37,7 +37,6 @@ module WorkPackages
end
end
-
validate :user_allowed_to_access
validate :user_allowed_to_edit
diff --git a/app/models/custom_actions/actions/date.rb b/app/models/custom_actions/actions/date.rb
index 1c4d096075..7440775d94 100644
--- a/app/models/custom_actions/actions/date.rb
+++ b/app/models/custom_actions/actions/date.rb
@@ -36,7 +36,7 @@ class CustomActions::Actions::Date < CustomActions::Actions::Base
end
def apply(work_package)
- work_package.start_date = values.first
- work_package.due_date = values.first
+ work_package.start_date = date_to_apply
+ work_package.due_date = date_to_apply
end
end
diff --git a/app/models/custom_actions/actions/strategies/date.rb b/app/models/custom_actions/actions/strategies/date.rb
index bf9e2e7077..c229345aad 100644
--- a/app/models/custom_actions/actions/strategies/date.rb
+++ b/app/models/custom_actions/actions/strategies/date.rb
@@ -37,10 +37,27 @@ module CustomActions::Actions::Strategies::Date
:date_property
end
- def to_date_or_nil(value)
- return nil if value.nil?
+ def apply(work_package)
+ work_package.send("#{self.class.key}=", date_to_apply)
+ end
+
+ private
- value.to_date
+ def date_to_apply
+ if values.first == '%CURRENT_DATE%'
+ Date.today
+ else
+ values.first
+ end
+ end
+
+ def to_date_or_nil(value)
+ case value
+ when nil, '%CURRENT_DATE%'
+ value
+ else
+ value.to_date
+ end
rescue TypeError, ArgumentError
nil
end
diff --git a/app/models/custom_actions/actions/strategies/date_property.rb b/app/models/custom_actions/actions/strategies/date_property.rb
index 138ca132a3..d8b9bcbb19 100644
--- a/app/models/custom_actions/actions/strategies/date_property.rb
+++ b/app/models/custom_actions/actions/strategies/date_property.rb
@@ -30,8 +30,4 @@
module CustomActions::Actions::Strategies::DateProperty
include CustomActions::Actions::Strategies::Date
-
- def apply(work_package)
- work_package.send("#{self.class.key}=", values.first)
- end
end
diff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erb
index 41de766233..a27bbaf79f 100644
--- a/app/views/custom_actions/_form.html.erb
+++ b/app/views/custom_actions/_form.html.erb
@@ -59,11 +59,9 @@
<% elsif %i(date_property).include?(action.type) %>
- <%= styled_text_field_tag input_name,
- action.values,
- container_class: '-slim',
- class: '-augmented-datepicker',
- size: '10' %>
+
+
<% elsif %i(string_property text_property).include?(action.type) %>
<%= styled_text_field_tag input_name,
action.values,
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 9f5d0e362e..62518b78ea 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -132,6 +132,11 @@ en:
button: 'Embed work package table'
text: '[Placeholder] Embedded work package table'
+ custom_actions:
+ date:
+ specific: 'on'
+ current_date: 'Current date'
+
error:
internal: "An internal error has occurred."
cannot_save_changes_with_message: "Cannot save your changes due to the following error: %{error}"
diff --git a/frontend/legacy/app/components/wp-custom-actions/date-action.component.html b/frontend/legacy/app/components/wp-custom-actions/date-action.component.html
new file mode 100644
index 0000000000..4f34914950
--- /dev/null
+++ b/frontend/legacy/app/components/wp-custom-actions/date-action.component.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
diff --git a/frontend/legacy/app/components/wp-custom-actions/date-action.component.ts b/frontend/legacy/app/components/wp-custom-actions/date-action.component.ts
new file mode 100644
index 0000000000..6734e7eaf7
--- /dev/null
+++ b/frontend/legacy/app/components/wp-custom-actions/date-action.component.ts
@@ -0,0 +1,99 @@
+// -- copyright
+// OpenProject is a project management system.
+// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
+//
+// 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 doc/COPYRIGHT.rdoc for more details.
+// ++
+
+import {openprojectLegacyModule} from "core-app/openproject-legacy-app";
+
+export class WpCustomActionsAdminDateActionComponent {
+ public valueVisible = false;
+ public fieldName:string;
+ public fieldValue:string;
+ public visibleValue:string;
+ public selectedOperator:any;
+ private i18n:any;
+
+ private onKey = 'on';
+ private currentKey = 'current';
+ private currentFieldValue = '%CURRENT_DATE%';
+
+ public operators:{key:string, label:string}[];
+
+ constructor() {
+ window.OpenProject.getPluginContext().then((context) => {
+ this.i18n = context.services.i18n;
+
+ this.initialize();
+ });
+ }
+
+ // cannot use $onInit as it would be called before the operators gets filled
+ public initialize() {
+ this.operators = [{key: this.onKey, label: this.i18n.t('js.custom_actions.date.specific')},
+ {key: this.currentKey, label: this.i18n.t('js.custom_actions.date.current_date')}];
+
+ if (this.fieldValue === this.currentFieldValue) {
+ this.selectedOperator = this.operators[1];
+ } else {
+ this.selectedOperator = this.operators[0];
+ this.visibleValue = this.fieldValue;
+ }
+
+ this.toggleValueVisibility();
+ }
+
+ public toggleValueVisibility() {
+ this.valueVisible = this.selectedOperator.key === this.onKey;
+ this.updateDbValue();
+ }
+
+ private updateDbValue() {
+ if (this.selectedOperator.key === this.currentKey) {
+ this.fieldValue = this.currentFieldValue;
+ } else {
+ this.fieldValue = this.visibleValue;
+ }
+ }
+
+ public get fieldId() {
+ // replace all square brackets by underscore
+ // to match the label's for value
+ return this.fieldName
+ .replace(/\[|\]/g, '_')
+ .replace('__', '_')
+ .replace(/_$/, '');
+ }
+}
+
+openprojectLegacyModule.component('wpCustomActionsAdminDateAction', {
+ template: require('!!raw-loader!./date-action.component.html'),
+ controller: WpCustomActionsAdminDateActionComponent,
+ bindings: {
+ fieldName: "@",
+ fieldValue: "@",
+ }
+});
+
diff --git a/frontend/src/app/angular4-modules.ts b/frontend/src/app/angular4-modules.ts
index ddde8c893b..22d31f1e29 100644
--- a/frontend/src/app/angular4-modules.ts
+++ b/frontend/src/app/angular4-modules.ts
@@ -348,8 +348,6 @@ import {WorkPackageByVersionGraphComponent} from "core-components/wp-by-version-
ZenModeButtonComponent,
WpResizerDirective,
MainMenuResizerComponent,
- WpCustomActionComponent,
- WpCustomActionsComponent,
WorkPackageTableSumsRowController,
SortHeaderDirective,
@@ -486,6 +484,10 @@ import {WorkPackageByVersionGraphComponent} from "core-components/wp-by-version-
EmbeddedTablesMacroComponent,
CkeditorAugmentedTextareaComponent,
+ // CustomActions
+ WpCustomActionComponent,
+ WpCustomActionsComponent,
+
// Attachments
AttachmentsComponent,
AttachmentListComponent,
@@ -501,7 +503,6 @@ import {WorkPackageByVersionGraphComponent} from "core-components/wp-by-version-
WorkPackageTablePaginationComponent,
WorkPackagesTableController,
TablePaginationComponent,
- WpCustomActionsComponent,
// Split view
WorkPackageSplitViewComponent,
@@ -574,6 +575,9 @@ import {WorkPackageByVersionGraphComponent} from "core-components/wp-by-version-
CkeditorAugmentedTextareaComponent,
EmbeddedTablesMacroComponent,
+ // CustomActions
+ WpCustomActionsComponent,
+
// Attachments
AttachmentsComponent,
diff --git a/frontend/src/app/components/wp-by-version-graph/wp-by-version-graph.template.html b/frontend/src/app/components/wp-by-version-graph/wp-by-version-graph.template.html
index 2d209205dd..a8c017cea6 100644
--- a/frontend/src/app/components/wp-by-version-graph/wp-by-version-graph.template.html
+++ b/frontend/src/app/components/wp-by-version-graph/wp-by-version-graph.template.html
@@ -1,6 +1,6 @@