Add topic creation for organisation users
This commit is contained in:
parent
15e1a2a32e
commit
215f46658e
7 changed files with 116 additions and 7 deletions
|
@ -15,6 +15,7 @@ import { DashboardCustomerComponent } from './dashboard-customer.component';
|
||||||
import { AccountEditComponent } from './account-edit.component';
|
import { AccountEditComponent } from './account-edit.component';
|
||||||
import { AddDataComponent } from './add-data.component';
|
import { AddDataComponent } from './add-data.component';
|
||||||
import { FeedbackComponent } from './feedback.component';
|
import { FeedbackComponent } from './feedback.component';
|
||||||
|
import { TopicsEditComponent } from './topics-edit.component';
|
||||||
import { SendPushNotificationComponent } from './send-push-notification.component';
|
import { SendPushNotificationComponent } from './send-push-notification.component';
|
||||||
import { TransactionLogComponent } from './transaction-log.component';
|
import { TransactionLogComponent } from './transaction-log.component';
|
||||||
import { CategoryMonthComponent } from './category-month.component';
|
import { CategoryMonthComponent } from './category-month.component';
|
||||||
|
@ -86,6 +87,7 @@ import { environment } from '../../environments/environment';
|
||||||
MapComponent,
|
MapComponent,
|
||||||
TrailMapComponent,
|
TrailMapComponent,
|
||||||
FeedbackComponent,
|
FeedbackComponent,
|
||||||
|
TopicsEditComponent,
|
||||||
SendPushNotificationComponent,
|
SendPushNotificationComponent,
|
||||||
GraphWidget,
|
GraphWidget,
|
||||||
OrgBarSnippetComponent,
|
OrgBarSnippetComponent,
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { MapComponent } from './map.component';
|
||||||
import { TrailMapComponent } from './trail-map.component';
|
import { TrailMapComponent } from './trail-map.component';
|
||||||
import { MoreStuffComponent } from './more-graphs-and-tables.component';
|
import { MoreStuffComponent } from './more-graphs-and-tables.component';
|
||||||
import { SuppliersComponent } from './suppliers.component';
|
import { SuppliersComponent } from './suppliers.component';
|
||||||
|
import { TopicsEditComponent } from './topics-edit.component';
|
||||||
import { SendPushNotificationComponent } from './send-push-notification.component';
|
import { SendPushNotificationComponent } from './send-push-notification.component';
|
||||||
|
|
||||||
// Using child path to allow for FullLayout theming
|
// Using child path to allow for FullLayout theming
|
||||||
|
@ -56,6 +57,16 @@ const routes: Routes = [
|
||||||
component: SendPushNotificationComponent,
|
component: SendPushNotificationComponent,
|
||||||
data: { title: 'Send Message' },
|
data: { title: 'Send Message' },
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'edit-topics',
|
||||||
|
component: TopicsEditComponent,
|
||||||
|
data: { title: 'Edit Topics' },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'edit-subscriptions',
|
||||||
|
component: SubscriptionsEditComponent,
|
||||||
|
data: { title: 'Edit Subscriptions' },
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'leaderboard',
|
path: 'leaderboard',
|
||||||
component: LeaderboardComponent,
|
component: LeaderboardComponent,
|
||||||
|
|
|
@ -43,10 +43,10 @@ export class SendPushNotificationComponent implements OnInit {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.loggedInEmail) {
|
if (!this.loggedInEmail) {
|
||||||
console.log('email not found in storage');
|
console.warn('email not found in storage');
|
||||||
this.api.accountFullLoad().subscribe(
|
this.api.accountFullLoad().subscribe(
|
||||||
result => {
|
result => {
|
||||||
console.log(result);
|
console.debug(result);
|
||||||
this.sendMessageForm.patchValue({
|
this.sendMessageForm.patchValue({
|
||||||
email: result.email,
|
email: result.email,
|
||||||
});
|
});
|
||||||
|
|
37
src/app/dashboard/topics-edit.component.html
Normal file
37
src/app/dashboard/topics-edit.component.html
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<div class="animated fadeIn">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-6 col-md-8">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-header">
|
||||||
|
<strong>Create New Topic</strong>
|
||||||
|
<small>Required Data marked in <strong>bold</strong>.</small>
|
||||||
|
</div>
|
||||||
|
<form class="form-horizontal" [formGroup]="createTopicForm" (ngSubmit)="onSubmit()">
|
||||||
|
<div class="card-block">
|
||||||
|
<div class="form-group row">
|
||||||
|
<label class="col-md-3 form-control-label" for="text-input"><strong>Enter Topic Name Here</strong></label>
|
||||||
|
<div class="col-md-9">
|
||||||
|
<input type="text" class="form-control" formControlName="topic" placeholder="Topic name">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-md-9">
|
||||||
|
<div [ngSwitch]="createTopicFormStatus">
|
||||||
|
<div *ngSwitchCase="'success'" class="alert alert-success" role="alert">
|
||||||
|
Topic has been created successfully!
|
||||||
|
</div>
|
||||||
|
<div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert">
|
||||||
|
{{createTopicFormStatusError}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="card-footer">
|
||||||
|
<button type="submit" [disabled]="!createTopicForm.valid" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i> Submit</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div><!--/.row-->
|
||||||
|
</div>
|
43
src/app/dashboard/topics-edit.component.ts
Normal file
43
src/app/dashboard/topics-edit.component.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { ApiService } from '../providers/api-service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
templateUrl: 'topics-edit.component.html',
|
||||||
|
})
|
||||||
|
export class TopicsEditComponen {
|
||||||
|
createTopicForm: FormGroup;
|
||||||
|
loggedInEmail: string;
|
||||||
|
createTopicFormStatus: string;
|
||||||
|
createTopicFormStatusSuccess: string;
|
||||||
|
createTopicFormStatusError = 'Error received, please try again.';
|
||||||
|
|
||||||
|
constructor(private api: ApiService) {
|
||||||
|
this.createTopicForm = new FormGroup({
|
||||||
|
topic: new FormControl('', Validators.required),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit(): void {
|
||||||
|
this.api
|
||||||
|
.createTopic(this.createTopicForm.value)
|
||||||
|
.subscribe(
|
||||||
|
result => {
|
||||||
|
console.debug('Topic successfully created.');
|
||||||
|
this.createTopicFormStatus = 'success';
|
||||||
|
this.createTopicForm.patchValue({
|
||||||
|
topic: '',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.error('Topic creation failed.');
|
||||||
|
try {
|
||||||
|
this.createTopicFormStatusError = '"' + error.error.error + '" Error, ' + error.error.message;
|
||||||
|
} catch (e) {
|
||||||
|
this.createTopicFormStatusError = 'There was a server error, please try again later.';
|
||||||
|
}
|
||||||
|
this.createTopicFormStatus = 'create_failed';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,6 +52,14 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li *ngIf="accountType == 'organisation'" class="nav-item">
|
||||||
|
<a class="nav-link" routerLinkActive="active" [routerLink]="['/edit-topics']">
|
||||||
|
<div class="row no-gutters align-items-center">
|
||||||
|
<div class="col-2"><i class="icon-feed"></i></div>
|
||||||
|
<div class="col-10">Manage Topics</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li *ngIf="accountType == 'organisation'" class="nav-item">
|
<li *ngIf="accountType == 'organisation'" class="nav-item">
|
||||||
<a class="nav-link" routerLinkActive="active" [routerLink]="['/notify']">
|
<a class="nav-link" routerLinkActive="active" [routerLink]="['/notify']">
|
||||||
<div class="row no-gutters align-items-center">
|
<div class="row no-gutters align-items-center">
|
||||||
|
|
|
@ -111,7 +111,7 @@ export class ApiService {
|
||||||
public checkDeviceToken(data) {
|
public checkDeviceToken(data) {
|
||||||
data.session_key = this.sessionKey;
|
data.session_key = this.sessionKey;
|
||||||
return this.http.post<any>(
|
return this.http.post<any>(
|
||||||
this.apiUrl + '/check-device-token',
|
this.apiUrl + '/device-token/check',
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ export class ApiService {
|
||||||
public addDeviceToken(data) {
|
public addDeviceToken(data) {
|
||||||
data.session_key = this.sessionKey;
|
data.session_key = this.sessionKey;
|
||||||
return this.http.post<any>(
|
return this.http.post<any>(
|
||||||
this.apiUrl + '/add-device-token',
|
this.apiUrl + '/device-token/add',
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -127,15 +127,23 @@ export class ApiService {
|
||||||
public getDeviceTokens() {
|
public getDeviceTokens() {
|
||||||
const key = this.sessionKey;
|
const key = this.sessionKey;
|
||||||
return this.http.post<any>(
|
return this.http.post<any>(
|
||||||
this.apiUrl + '/get-device-tokens',
|
this.apiUrl + '/device-tokens',
|
||||||
{ session_key : key }
|
{ session_key : key }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createTopic(data) {
|
||||||
|
data.session_key = this.sessionKey;
|
||||||
|
return this.http.post<any>(
|
||||||
|
this.apiUrl + '/topic/add',
|
||||||
|
data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public getTopics() {
|
public getTopics() {
|
||||||
const key = this.sessionKey;
|
const key = this.sessionKey;
|
||||||
return this.http.post<any>(
|
return this.http.post<any>(
|
||||||
this.apiUrl + '/get-topics',
|
this.apiUrl + '/topics',
|
||||||
{ session_key : key }
|
{ session_key : key }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue