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

Move methods from service to components back again

Inga Maia20c29854388
diff --git a/frontend/src/app/components/enterprise/enterprise-active-trial/ee-active-trial.component.ts b/frontend/src/app/components/enterprise/enterprise-active-trial/ee-active-trial.component.ts
index 5c908e9e997..f8c30683eb0 100644
--- a/frontend/src/app/components/enterprise/enterprise-active-trial/ee-active-trial.component.ts
+++ b/frontend/src/app/components/enterprise/enterprise-active-trial/ee-active-trial.component.ts
@@ -28,8 +28,9 @@
import {Component, ElementRef, OnInit} from "@angular/core";
import {I18nService} from "app/modules/common/i18n/i18n.service";
-import {EnterpriseTrialService} from "app/components/enterprise/enterprise-trial.service";
+import {baseUrlAugur, EnterpriseTrialService} from "app/components/enterprise/enterprise-trial.service";
import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper";
+import {HttpClient, HttpErrorResponse} from "@angular/common/http";
@Component({
selector: 'enterprise-active-trial',
@@ -37,6 +38,8 @@ import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper";
styleUrls: ['./ee-active-trial.component.sass']
})
export class EEActiveTrialComponent implements OnInit {
+ public initialData:any;
+
public text = {
label_email: this.I18n.t('js.admin.enterprise.trial.form.label_email'),
label_expires_at: this.I18n.t('js.admin.enterprise.trial.form.label_expires_at'),
@@ -44,6 +47,7 @@ export class EEActiveTrialComponent implements OnInit {
label_starts_at: this.I18n.t('js.admin.enterprise.trial.form.label_starts_at'),
label_subscriber: this.I18n.t('js.admin.enterprise.trial.form.label_subscriber')
};
+
public subscriber = this.elementRef.nativeElement.dataset['subscriber'];
public email = this.elementRef.nativeElement.dataset['email'];
public userCount = this.elementRef.nativeElement.dataset['userCount'];
@@ -52,18 +56,51 @@ export class EEActiveTrialComponent implements OnInit {
constructor(readonly elementRef:ElementRef,
readonly I18n:I18nService,
+ protected http:HttpClient,
public eeTrialService:EnterpriseTrialService) {
}
ngOnInit() {
// trial is not active yet
if (!this.subscriber) {
- // get user data from service
- setTimeout(() => {
- let savedData = this.eeTrialService.trialForm.value;
- this.subscriber = savedData.first_name + ' ' + savedData.last_name;
- this.email = savedData.email;
- }, 500);
+ this.initialize();
+ }
+ }
+
+ // initialize attributes with submitted user data
+ private initialize():void {
+ this.initialData = this.loadGonData();
+
+ if (!this.initialData) { // get data from service
+ this.subscriber = this.eeTrialService.userData.subscriber;
+ this.email = this.eeTrialService.userData.email;
+ } else { // after reload: get data from Augur using the trial key saved in gon
+ this.eeTrialService.trialLink = baseUrlAugur + '/public/v1/trials/' + this.initialData.value;
+ this.getUserDataFromAugur();
+ }
+ }
+
+ // use the trial key saved in the db
+ // to get the user data from Augur
+ private getUserDataFromAugur() {
+ this.http
+ .get<any>(this.eeTrialService.trialLink + '/details')
+ .toPromise()
+ .then((userData:any) => {
+ this.subscriber = userData.first_name + ' ' + userData.last_name;
+ this.email = userData.email;
+ this.eeTrialService.retryConfirmation(this.eeTrialService.delay, this.eeTrialService.retries);
+ })
+ .catch((error:HttpErrorResponse) => {
+ this.eeTrialService.cancelled = true;
+ });
+ }
+
+ private loadGonData():{value:string}|null {
+ try {
+ return (window as any).gon.ee_trial_key;
+ } catch (e) {
+ return null;
}
}
}
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
index eeec7d3814f..986c5d49828 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.html
@@ -32,7 +32,8 @@
<div class="form--field -wide-label -required" [ngClass]="{ '-error': eeTrialService.errorMsg }">
<label class="form--label">{{ text.label_email }}</label>
<div class="form--field-container">
- <div class="form--text-field-container">
+ <div class="form--text-field-container"
+ [ngClass]="{'-required-highlighting' : eeTrialService.errorMsg}">
<input type="email" class="form--text-field" formControlName="email" (blur)="checkMailField()">
</div>
</div>
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.sass b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.sass
index 9d1c2057b7f..30aa4a1300a 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.sass
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial-form/ee-trial-form.component.sass
@@ -6,5 +6,3 @@
.form--label,
.form--label::after
color: var(--content-form-danger-zone-bg-color)
- .form--text-field
- border: 1px solid var(--content-form-danger-zone-bg-color)
\ No newline at end of file
diff --git a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
index 73e7f688ce5..2f8efd773ac 100644
--- a/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
+++ b/frontend/src/app/components/enterprise/enterprise-modal/enterprise-trial.modal.ts
@@ -46,10 +46,6 @@ export class EnterpriseTrialModal extends OpModalComponent implements AfterViewI
@Input() public opReferrer:string;
public trialForm:FormGroup;
-
- public confirmed:boolean;
- public cancelled = false;
- public status:string;
public errorMsg:string|undefined;
// modal configuration
@@ -87,8 +83,6 @@ export class EnterpriseTrialModal extends OpModalComponent implements AfterViewI
public onSubmit() {
if (this.trialForm.valid) {
this.trialForm.addControl('_type', new FormControl('enterprise-trial'));
-
- this.eeTrialService.cancelled = false;
this.eeTrialService.sendForm(this.trialForm);
}
}
diff --git a/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html b/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
index 7db2b2a8e2a..5007947104e 100644
--- a/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
+++ b/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.html
@@ -5,7 +5,7 @@
<span>{{ text.status_label }} </span>
<span *ngIf="!eeTrialService.confirmed; else confirmedStatus" class="status--waiting">
{{ text.status_waiting }}
- <a id="resend-link" (click)="eeTrialService.resendMail()">{{ text.resend }}</a>
+ <a id="resend-link" (click)="resendMail()">{{ text.resend }}</a>
<p *ngIf="eeTrialService.cancelled">{{ text.session_timeout }}</p>
</span>
diff --git a/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts b/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
index 7bd6aae3cb7..d9e7100db25 100644
--- a/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
+++ b/frontend/src/app/components/enterprise/enterprise-trial-waiting/ee-trial-waiting.component.ts
@@ -29,6 +29,9 @@
import {Component, ElementRef} from "@angular/core";
import {I18nService} from "app/modules/common/i18n/i18n.service";
import {EnterpriseTrialService} from "app/components/enterprise/enterprise-trial.service";
+import {HttpClient, HttpErrorResponse} from "@angular/common/http";
+import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";
+
@Component({
selector: 'enterprise-trial-waiting',
@@ -39,6 +42,8 @@ export class EETrialWaitingComponent {
public text = {
confirmation_info: this.I18n.t('js.admin.enterprise.trial.confirmation_info'),
resend: this.I18n.t('js.admin.enterprise.trial.resend_link'),
+ resend_success: this.I18n.t('js.admin.enterprise.trial.resend_success'),
+ resend_warning: this.I18n.t('js.admin.enterprise.trial.resend_warning'),
session_timeout: this.I18n.t('js.admin.enterprise.trial.session_timeout'),
status_confirmed: this.I18n.t('js.admin.enterprise.trial.status_confirmed'),
status_label: this.I18n.t('js.admin.enterprise.trial.status_label'),
@@ -47,7 +52,23 @@ export class EETrialWaitingComponent {
constructor(readonly elementRef:ElementRef,
readonly I18n:I18nService,
+ protected http:HttpClient,
+ protected notificationsService:NotificationsService,
public eeTrialService:EnterpriseTrialService) {
}
+
+ // resend mail if resend link has been clicked
+ public resendMail() {
+ this.eeTrialService.cancelled = false;
+ this.http.post(this.eeTrialService.resendLink, {})
+ .toPromise()
+ .then(() => {
+ this.notificationsService.addSuccess(this.text.resend_success);
+ this.eeTrialService.retryConfirmation(this.eeTrialService.delay, this.eeTrialService.retries);
+ })
+ .catch((error:HttpErrorResponse) => {
+ this.notificationsService.addError(this.text.resend_warning);
+ });
+ }
}
diff --git a/frontend/src/app/components/enterprise/enterprise-trial.service.ts b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
index b62e5bd37bd..55318b250fb 100644
--- a/frontend/src/app/components/enterprise/enterprise-trial.service.ts
+++ b/frontend/src/app/components/enterprise/enterprise-trial.service.ts
@@ -5,17 +5,12 @@ import {PathHelperService} from "core-app/modules/common/path-helper/path-helper
import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";
import {FormBuilder, FormGroup} from "@angular/forms";
+export const baseUrlAugur = 'https://augur.openproject-edge.com';
@Injectable()
export class EnterpriseTrialService {
- public text = {
- resend_success: this.I18n.t('js.admin.enterprise.trial.resend_success'),
- resend_warning: this.I18n.t('js.admin.enterprise.trial.resend_warning')
- };
+ public userData:{subscriber:string, email:string};
- public trialForm:FormGroup;
- public initialData:any;
- public baseUrlAugur = 'https://augur.openproject-edge.com';
public trialLink:string;
public resendLink:string;
@@ -26,35 +21,29 @@ export class EnterpriseTrialService {
public errorMsg:string|undefined;
// retry confirmation
- private delay = 5000; // wait 5s until next request
- private retries = 60; // keep trying for 5 minutes
+ public delay = 5000; // wait 5s until next request
+ public retries = 60; // keep trying for 5 minutes
constructor(readonly I18n:I18nService,
protected http:HttpClient,
readonly pathHelper:PathHelperService,
protected notificationsService:NotificationsService,
readonly formBuilder:FormBuilder) {
- this.initialize();
- }
-
- // check if a user already submitted user data
- // initialize the trial form with this data saved in Augur
- private initialize():void {
- this.initialData = this.loadGonData();
- // user has already submitted a valid mail and received a confirmation link
- if (this.initialData) {
- this.trialLink = this.baseUrlAugur + '/public/v1/trials/' + this.initialData.value;
- this.getUserDataFromAugur(this.initialData.value);
+ if ((window as any).gon) {
+ this.status = 'mailSubmitted';
}
}
// send POST request with form object
// receive an enterprise trial link to access a token
public sendForm(form:FormGroup) {
- this.trialForm = form;
-
+ this.userData = {
+ subscriber: form.value.first_name + ' ' + form.value.last_name,
+ email: form.value.email
+ };
+ this.cancelled = false;
// POST /public/v1/trials/
- this.http.post(this.baseUrlAugur + '/public/v1/trials', this.trialForm.value)
+ this.http.post(baseUrlAugur + '/public/v1/trials', form.value)
.toPromise()
.then((enterpriseTrial:any) => {
this.trialLink = enterpriseTrial._links.self.href;
@@ -101,7 +90,7 @@ export class EnterpriseTrialService {
// get resend button link
this.resendLink = error.error._links.resend.href;
// save a key for the requested trial
- if (!this.status) { // only do it once
+ if (!this.status || this.cancelled) { // only do it once
this.saveTrialKey(this.resendLink);
}
// open next modal window -> status waiting
@@ -164,43 +153,4 @@ export class EnterpriseTrialService {
}, delay);
}
}
-
- // resend mail if resend link has been clicked
- public resendMail() {
- this.http.post(this.resendLink, {})
- .toPromise()
- .then(() => {
- this.notificationsService.addSuccess(this.text.resend_success);
-
- this.cancelled = false;
- this.retryConfirmation(this.delay, this.retries);
- })
- .catch((error:HttpErrorResponse) => {
- this.cancelled = false;
- this.notificationsService.addError(this.text.resend_warning);
- });
- }
-
- // use the trial key saved in the db
- // to get the user data from Augur
- private getUserDataFromAugur(trialKey:string) {
- this.http
- .get<any>(this.baseUrlAugur + '/public/v1/trials/' + trialKey + '/details')
- .toPromise()
- .then((userData:any) => {
- this.trialForm = this.formBuilder.group(userData);
- this.retryConfirmation(this.delay, this.retries);
- })
- .catch((error:HttpErrorResponse) => {
- this.cancelled = true;
- });
- }
-
- private loadGonData():{value:string}|null {
- try {
- return (window as any).gon.ee_trial_key;
- } catch (e) {
- return null;
- }
- }
}
\ No newline at end of file