diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 4ec1729b..02da5bfc 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -19,30 +19,31 @@ import { VotingComponent } from './pages/voting/voting.component'; import { PollGraphicComponent } from './poll-graphic/poll-graphic.component'; const routes: Routes = [ - { path: '', redirectTo: 'step/creation', pathMatch: 'full' }, - { path: 'home', component: HomeComponent }, - { path: 'base', component: BaseComponent }, - { path: 'step/base', component: BaseComponent }, - { path: 'step/creation', component: CreateOrRetrieveComponent }, - { path: 'step/date', component: DatesComponent }, - { path: 'step/kind', component: KindComponent }, - { path: 'step/answers', component: AnswersComponent }, - { path: 'step/admin', component: AdminComponent }, - { path: 'step/pictures', component: PicturesComponent }, - { path: 'step/visibility', component: VisibilityComponent }, - { path: 'step/resume', component: ResumeComponent }, - { path: 'step/end', component: EndConfirmationComponent }, - { path: 'graphic/:poll', component: PollGraphicComponent }, - { path: 'vote/poll/id/:poll', component: PollDisplayComponent }, - { path: 'vote/poll/slug/:pollSlug', component: PollDisplayComponent }, - { path: 'votingchoice', component: VotingChoiceComponent }, - { path: 'voting', component: VotingComponent }, - { path: 'step/password', component: PasswordComponent }, - { path: '**', redirectTo: '/home', pathMatch: 'full' }, + { path: '', redirectTo: 'step/creation', pathMatch: 'full' }, + { path: 'admin/:token', component: AdminComponent }, // http://localhost:4200/#/admin/srfdgedsTGETHRYJtujTUjTUkTIUKTK + { path: 'home', component: HomeComponent }, + { path: 'base', component: BaseComponent }, + { path: 'step/base', component: BaseComponent }, + { path: 'step/creation', component: CreateOrRetrieveComponent }, + { path: 'step/date', component: DatesComponent }, + { path: 'step/kind', component: KindComponent }, + { path: 'step/answers', component: AnswersComponent }, + { path: 'step/admin', component: AdminComponent }, + { path: 'step/pictures', component: PicturesComponent }, + { path: 'step/visibility', component: VisibilityComponent }, + { path: 'step/resume', component: ResumeComponent }, + { path: 'step/end', component: EndConfirmationComponent }, + { path: 'graphic/:poll', component: PollGraphicComponent }, + { path: 'vote/poll/id/:poll', component: PollDisplayComponent }, + { path: 'vote/poll/slug/:pollSlug', component: PollDisplayComponent }, + { path: 'votingchoice', component: VotingChoiceComponent }, + { path: 'voting', component: VotingComponent }, + { path: 'step/password', component: PasswordComponent }, + { path: '**', redirectTo: '/home', pathMatch: 'full' }, ]; @NgModule({ - imports: [RouterModule.forRoot(routes, { useHash: true, anchorScrolling: 'enabled' })], - exports: [RouterModule], + imports: [RouterModule.forRoot(routes, { useHash: true, anchorScrolling: 'enabled' })], + exports: [RouterModule], }) export class AppRoutingModule {} diff --git a/src/app/config/Routes.ts b/src/app/config/Routes.ts index 78455a40..4a96f1d2 100644 --- a/src/app/config/Routes.ts +++ b/src/app/config/Routes.ts @@ -1,42 +1,4 @@ -import { AdminComponent } from '../pages/admin/admin.component'; -import { AnswersComponent } from '../pages/answers/answers.component'; -import { BaseComponent } from '../pages/base-page/base.component'; -import { CreateOrRetrieveComponent } from '../pages/create-or-retrieve/create-or-retrieve.component'; -import { DatesComponent } from '../pages/dates/dates.component'; -import { EndConfirmationComponent } from '../pages/end-confirmation/end-confirmation.component'; -import { HomeComponent } from '../pages/home/home.component'; -import { KindComponent } from '../pages/kind/kind.component'; -import { PasswordComponent } from '../pages/password/password.component'; -import { PicturesComponent } from '../pages/pictures/pictures.component'; -import { PollDisplayComponent } from '../pages/poll-display/poll-display.component'; -import { ResumeComponent } from '../pages/resume/resume.component'; -import { VisibilityComponent } from '../pages/visibility/visibility.component'; -import { VotingChoiceComponent } from '../pages/voting/voting-choice/voting-choice.component'; -import { VotingComponent } from '../pages/voting/voting.component'; -import { PollGraphicComponent } from '../poll-graphic/poll-graphic.component'; - /** * each step in the form is a component */ -export const Routes = [ - { path: '', redirectTo: 'step/creation', pathMatch: 'full' }, - { path: 'home', component: HomeComponent }, - { path: 'base', component: BaseComponent }, - { path: 'step/base', component: BaseComponent }, - { path: 'step/creation', component: CreateOrRetrieveComponent }, - { path: 'step/date', component: DatesComponent }, - { path: 'step/kind', component: KindComponent }, - { path: 'step/answers', component: AnswersComponent }, - { path: 'step/admin', component: AdminComponent }, - { path: 'step/pictures', component: PicturesComponent }, - { path: 'step/visibility', component: VisibilityComponent }, - { path: 'step/resume', component: ResumeComponent }, - { path: 'step/end', component: EndConfirmationComponent }, - { path: 'graphic/:poll', component: PollGraphicComponent }, - { path: 'vote/poll/id/:poll', component: PollDisplayComponent }, - { path: 'vote/poll/slug/:pollSlug', component: PollDisplayComponent }, - { path: 'votingchoice', component: VotingChoiceComponent }, - { path: 'voting', component: VotingComponent }, - { path: 'step/password', component: PasswordComponent }, - { path: '**', redirectTo: '/home', pathMatch: 'full' }, -]; +export const Routes = []; diff --git a/src/app/pages/admin/admin.component.html b/src/app/pages/admin/admin.component.html index 6175bd5c..f5881e2d 100644 --- a/src/app/pages/admin/admin.component.html +++ b/src/app/pages/admin/admin.component.html @@ -1,148 +1,10 @@ -
-

Nom du sondage

- - -

{{ 'admin.info_section_title' | translate }}

- - - - - - - - - - - -

{{ 'admin.settings_section_title' | translate }}

-

{{ 'visibility.title' | translate }}

- -
- - - -
- -

{{ 'visibility.votes' | translate }}

-
- - -
-
- - - - -
- - - - -

{{ 'admin.comments_deletion_title' | translate }}

- - - - -

{{ 'admin.archiving_title' | translate }}

-
- - -
- -

{{ 'visibility.access' | translate }}

-
- - - -
- -

{{ 'admin.deletion' | translate }}

- - - - -

{{ 'admin.link' | translate }}

-

{{ 'admin.link_admin' | translate }}

- - - - - -

{{ 'admin.polled_people' | translate }}

- - - - -

{{ 'admin.email_links' | translate }}

- - - -
- +
+

+ admin page to modify a poll +

+
+

Anybody with this link can modify and delete the poll

+ token: {{ tokenForAdministration }} + coming soon +
+
diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index dfe5a381..316fea19 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -1,13 +1,61 @@ import { Component, OnInit } from '@angular/core'; import { ConfigService } from '../../services/config.service'; +import { ActivatedRoute, Router } from '@angular/router'; +import { HttpClient } from '@angular/common/http'; +import { PollUtilities } from '../../config/PollUtilities'; +import { environment } from '../../../environments/environment'; @Component({ - selector: 'framadate-admin', - templateUrl: './admin.component.html', - styleUrls: ['./admin.component.scss'], + selector: 'framadate-admin', + templateUrl: './admin.component.html', + styleUrls: ['./admin.component.scss'], }) export class AdminComponent implements OnInit { - constructor(public config: ConfigService) {} + public tokenForAdministration = ''; - ngOnInit() {} + constructor( + public config: ConfigService, + public router: Router, + private utils: PollUtilities, + public http: HttpClient, + public activeRoute: ActivatedRoute + ) {} + + ngOnInit() { + this.activeRoute.paramMap.subscribe((params) => { + console.log('params', params); + this.tokenForAdministration = params.get('token'); + // redirect to home if no token provided + if (!this.tokenForAdministration) { + alert('pas de token pour administrer un sondage, mauvaise URL.'); + this.router.navigate(['/home']); + } + if (!this.config.loading) { + // get token paarameter from route + // fetch admin version of the poll + // then, populate UI. + this.fetchPoll(); + } + }); + } + + // fetch poll with its ID or slug. + fetchPoll() { + const token = this.tokenForAdministration; + const headers = this.utils.makeHeaders({ token: token }); + this.config.loading = true; + // store it in the poll property here + this.http.get(`${environment.baseApiHref}/admin/${token}`, headers).subscribe( + (res: any) => { + console.log('res', res); + this.config.updateCurrentPollFromResponse(res); + this.config.loading = false; + }, + (e) => { + // handle need for a password + console.log('e', e); + this.config.handleError(e); + } + ); + } }