Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

implemented feedback from @ulferts towards modal behavior and api format (WIP)

Jonas Jabari5c3c47494bff
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 11cdb51bd31..86fc7f51517 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -358,11 +358,14 @@ en:
ical_sharing_modal:
title: "Share iCalendar"
- description_1: "You can use the"
- description_2: "to import or subscribe to this calendar in an external client and view up-to-date work package information from there."
+ inital_setup_error_message: "An error occured while fetching data"
+ inital_setup_error_message: "An error occured while fetching data"
+ description: "You can use the iCalendar URL to import or subscribe to this calendar in an external client and view up-to-date work package information from there."
warning: "You can also share this URL with external users. However, anyone with this link will be able to view work package details without an account or password."
copy_url_label: "Copy URL"
+ ical_generation_error_text: "An error occured while generating the iCal URL"
copy_url_success_text: "URL copied to clipboard"
+ copy_url_error_text: "couldn't be copied to clipboard"
label_activate: "Activate"
label_assignee: 'Assignee'
diff --git a/frontend/src/app/core/apiv3/endpoints/queries/apiv3-queries-paths.ts b/frontend/src/app/core/apiv3/endpoints/queries/apiv3-queries-paths.ts
index 56b40072c4f..032d1780f19 100644
--- a/frontend/src/app/core/apiv3/endpoints/queries/apiv3-queries-paths.ts
+++ b/frontend/src/app/core/apiv3/endpoints/queries/apiv3-queries-paths.ts
@@ -139,6 +139,6 @@ export class ApiV3QueriesPaths extends ApiV3ResourceCollection<QueryResource, Ap
* @param query
*/
public getIcalUrl(query:QueryResource):Promise<unknown> {
- return query.getIcalUrl();
+ return query.icalUrl();
}
}
diff --git a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
index 5a8f5f0343c..a09e3108483 100644
--- a/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
+++ b/frontend/src/app/features/work-packages/openproject-work-packages.module.ts
@@ -125,6 +125,7 @@ import { OpenprojectAutocompleterModule } from 'core-app/shared/components/autoc
import { OpWpTabsModule } from 'core-app/features/work-packages/components/wp-tabs/wp-tabs.module';
import { EditFieldControlsModule } from 'core-app/shared/components/fields/edit/field-controls/edit-field-controls.module';
import { WpTableExportModalComponent } from 'core-app/shared/components/modals/export-modal/wp-table-export.modal';
+import { QueryGetIcalUrlModalComponent } from 'core-app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal';
import { WpButtonMacroModalComponent } from 'core-app/shared/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal';
import { QuerySharingModalComponent } from 'core-app/shared/components/modals/share-modal/query-sharing.modal';
import { SaveQueryModalComponent } from 'core-app/shared/components/modals/save-modal/save-query.modal';
@@ -385,6 +386,7 @@ import { StorageFilesResourceService } from 'core-app/core/state/storage-files/s
WpTableConfigurationHighlightingTabComponent,
WpTableConfigurationRelationSelectorComponent,
WpTableExportModalComponent,
+ QueryGetIcalUrlModalComponent,
QuerySharingFormComponent,
QuerySharingModalComponent,
SaveQueryModalComponent,
diff --git a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.html b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.html
index 9e86e086a6d..e6fee41fe16 100644
--- a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.html
+++ b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.html
@@ -8,9 +8,7 @@
<div class="spot-modal--body spot-container">
<p>
- {{text.description_ical_sharing_1}}
- <a href="{{icalUrl}}" target="_blank">iCalendar URL</a>
- {{text.description_ical_sharing_2}}
+ {{text.description_ical_sharing}}
</p>
<div tabindex="0" class="-error op-toast">
<div role="alert" aria-atomic="true" class="op-toast--content">
@@ -21,8 +19,6 @@
</div>
</div>
-
-
<div class="spot-action-bar">
<div class="spot-action-bar--right">
<button class="button button_no-margin spot-modal--cancel-button spot-action-bar--action"
@@ -30,8 +26,9 @@
(click)="closeMe($event)">
</button>
<button class="button button_no-margin -highlight -with-icon icon-copy spot-action-bar--action"
- (click)="copyUrl()"
- [textContent]="text.button_copy">
+ (click)="generateAndCopyUrl()"
+ [textContent]="text.button_copy"
+ [disabled]="isBusy">
</button>
</div>
</div>
diff --git a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
index b3bf5540ad4..5751c5789a6 100644
--- a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
+++ b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
@@ -40,6 +40,8 @@ import { I18nService } from 'core-app/core/i18n/i18n.service';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { QueryResource } from 'core-app/features/hal/resources/query-resource';
+import { timeout } from 'rxjs/operators';
@Component({
templateUrl: './query-get-ical-url.modal.html',
@@ -47,14 +49,13 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class QueryGetIcalUrlModalComponent extends OpModalComponent implements OnInit {
- public isBusy = false;
+ public query:QueryResource;
- public icalUrl:string;
+ public isBusy = false;
public text = {
label_ical_sharing: this.I18n.t('js.ical_sharing_modal.title'),
- description_ical_sharing_1: this.I18n.t('js.ical_sharing_modal.description_1'),
- description_ical_sharing_2: this.I18n.t('js.ical_sharing_modal.description_2'),
+ description_ical_sharing: this.I18n.t('js.ical_sharing_modal.description'),
ical_sharing_warning: this.I18n.t('js.ical_sharing_modal.warning'),
button_copy: this.I18n.t('js.ical_sharing_modal.copy_url_label'),
copy_success_text: this.I18n.t('js.ical_sharing_modal.copy_url_success_text'),
@@ -80,40 +81,60 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements O
ngOnInit():void {
super.ngOnInit();
- const query = this.querySpace.query.value;
+ this.query = this.querySpace.query.value!;
+
+ // TODO: I'm not sure if this is an error we actually need to catch
+ if (!this.query) {
+ this.toastService.addError(
+ this.I18n.t('js.ical_sharing_modal.inital_setup_error_message')
+ );
+ // without timeout the modal backdrop is not removed
+ setTimeout(() => {
+ this.closeMe();
+ }, 10);
+ }
+ }
- if (!query) {
+ public copyUrlAndCloseModal(url:string):void {
+ void navigator.clipboard.writeText(url)
+ .then(() => {
+ this.toastService.addSuccess(this.text.copy_success_text);
+ this.closeMe();
+ })
+ .catch(() => {
+ // e.g. browser permission errors
+ this.toastService.addError(
+ url + " " + this.I18n.t('js.ical_sharing_modal.copy_url_error_text')
+ );
+ });
+ }
+
+ public generateAndCopyUrl():void {
+ if (this.isBusy) {
return;
}
+ let icalUrl = "";
+
+ this.isBusy = true;
+
const promise = this
.apiV3Service
.queries
- .getIcalUrl(query);
-
- this.isBusy = true;
+ .getIcalUrl(this.query);
void promise
.then((response:HalResource) => {
- this.icalUrl = String(response.icalUrl);
+ icalUrl = String(response.icalUrl.href);
+ this.copyUrlAndCloseModal(icalUrl);
+ })
+ .catch(() => {
this.isBusy = false;
this.cdRef.detectChanges();
- // TODO: or would that be better?
- // this.ngZone.run(() => {
- // this.icalUrl = response.icalUrl;
- // this.isBusy = false;
- // });
- });
- }
- public copyUrl():void {
- if (this.isBusy) {
- return;
- }
-
- void navigator.clipboard.writeText(this.icalUrl)
- .then(() => {
- this.toastService.addSuccess(this.text.copy_success_text);
+ this.toastService.addError(
+ this.I18n.t('js.ical_sharing_modal.ical_generation_error_text')
+ );
});
}
}
diff --git a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
index 6e86fb8f285..9b9cbbf6fad 100644
--- a/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
+++ b/frontend/src/app/shared/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts
@@ -316,11 +316,11 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger {
{
// Calendar sharing modal
hidden: !this.showCalendarSharingOption,
- disabled: this.authorisationService.cannot('query', 'getIcalUrl'),
+ disabled: this.authorisationService.cannot('query', 'icalUrl'),
linkText: this.I18n.t('js.toolbar.settings.share_calendar'),
icon: 'icon-link', // TODO: find sharing icons
onClick: () => {
- if (this.authorisationService.can('query', 'getIcalUrl')) {
+ if (this.authorisationService.can('query', 'icalUrl')) {
this.opModalService.show(QueryGetIcalUrlModalComponent, this.injector);
}
diff --git a/lib/api/v3/queries/queries_api.rb b/lib/api/v3/queries/queries_api.rb
index 6a0f3bf51d6..5e6fc9028b6 100644
--- a/lib/api/v3/queries/queries_api.rb
+++ b/lib/api/v3/queries/queries_api.rb
@@ -159,7 +159,7 @@ module API
.mount
end
- namespace :create_ical_url do
+ namespace :ical_url do
post do
authorize_by_policy(:share_via_ical)
@@ -171,8 +171,22 @@ module API
project_id: @query.project_id
)
+ # TODO: use representer in order to properly generate following response
+ # TODO: write test for this
{
- icalUrl: call.result
+ "_type": "QueryICalUrl",
+ "_links": {
+ "self": {
+ "href": api_v3_paths.query_ical_url(@query.id)
+ },
+ "query": {
+ "href": api_v3_paths.query(@query.id)
+ },
+ "icalUrl": {
+ "href": call.result,
+ "format": "text/calendar"
+ }
+ }
}
end
end
diff --git a/lib/api/v3/queries/query_representer.rb b/lib/api/v3/queries/query_representer.rb
index 4d7f8a52838..eae2d8a8811 100644
--- a/lib/api/v3/queries/query_representer.rb
+++ b/lib/api/v3/queries/query_representer.rb
@@ -147,12 +147,12 @@ module API
}
end
- link :getIcalUrl do
+ link :icalUrl do
next if represented.new_record? ||
!allowed_to?(:share_via_ical)
{
- href: api_v3_paths.query_create_ical_url(represented.id),
+ href: api_v3_paths.query_ical_url(represented.id),
method: :post
}
end
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 3ad9ef45c9e..a5535a2a9bc 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -329,8 +329,8 @@ module API
"#{query(id)}/order"
end
- def self.query_create_ical_url(id)
- "#{query(id)}/create_ical_url"
+ def self.query_ical_url(id)
+ "#{query(id)}/ical_url"
end
def self.query_column(name)
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index 0482fc1520d..ee448efd50f 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -121,13 +121,11 @@ describe 'Calendar sharing via ical', js: true do
# expect disabled sharing menu item
within "#settingsDropdown" do
- # expect(page).to have_button("Share iCalendar", disabled: true) # disabled selector not working
expect(page).to have_selector(".menu-item", text: "Share iCalendar")
page.click_button("Share iCalendar")
end
expect(page).to have_selector('.spot-modal--header', text: "Share iCalendar")
- expect(page).to have_xpath('//a[contains(@href, "/ical?ical_token=")]')
click_button "Copy URL"