Merge branch 'admin-routing' into 'develop'

Admin routing

See merge request framasoft/framadate/funky-framadate-front!30
This commit is contained in:
seraph_ino 2020-04-17 22:24:48 +02:00
commit 88fec2c0c6
4 changed files with 87 additions and 214 deletions

View File

@ -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 {}

View File

@ -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 = [];

View File

@ -1,148 +1,10 @@
<form>
<h1>Nom du sondage</h1>
<!--Infos-->
<h2>{{ 'admin.info_section_title' | translate }}</h2>
<label for="title">
{{ 'admin.choose_title' | translate }}
</label>
<input type="text" name="title" />
<label for="desc">
{{ 'admin.description' | translate }}
</label>
<textarea name="desc"> </textarea>
<label for="name">
{{ 'creation.name' | translate }}
</label>
<input type="text" name="name" />
<!--Params-->
<h2>{{ 'admin.settings_section_title' | translate }}</h2>
<h3>{{ 'visibility.title' | translate }}</h3>
<section class="row">
<label for="answer-visible">
{{ 'visibility.visibility_want' | translate }}
</label>
<select name="answer-visible">
<option value="all" selected>
{{ 'visibility.visibility_link' | translate }}
</option>
<option value="per">
{{ 'visibility.visibility_nobody' | translate }}
</option>
</select>
<label for="answer-visible">
{{ 'visibility.visibility_see' | translate }}
</label>
</section>
<h3>{{ 'visibility.votes' | translate }}</h3>
<section>
<label for="vote-date">
{{ 'visibility.archiving' | translate }}
</label>
<input type="date" name="vote-date" />
</section>
<section>
<label for="alter-vote">
{{ 'visibility.archiving_start' | translate }}
</label>
<select name="alter-vote">
<option value="yes" selected>
{{ 'visibility.archiving_can' | translate }}
</option>
<option value="no">
{{ 'visibility.archiving_can_not' | translate }}
</option>
</select>
<label for="type-vote">
{{ 'visibility.archiving_end' | translate }}
</label>
<select name="type-vote">
<option value="solo" selected>
{{ 'visibility.modfiy_their' | translate }}
</option>
<option value="all">
{{ 'visibility.modfiy_everyone' | translate }}
</option>
</select>
</section>
<label for="del-vote">
{{ 'admin.votes_deletion_desc' | translate }}
</label>
<button class="btn btn--alert btn--outline" (click)="config.deleteVotes()">
<i class="fa fa-trash"></i>
{{ 'admin.votes_deletion_btn' | translate }}
<i class="fa fa-object-group"></i>
</button>
<h3>{{ 'admin.comments_deletion_title' | translate }}</h3>
<label for="del-com">
{{ 'admin.comments_deletion_desc' | translate }}
</label>
<button class="btn btn--alert btn--outline" (click)="config.deleteComments()">
<i class="fa fa-trash"></i>
{{ 'admin.comments_deletion_btn' | translate }}
<i class="fa fa-comments-o"></i>
</button>
<h3>{{ 'admin.archiving_title' | translate }}</h3>
<section class="row">
<label for="arch">
{{ 'admin.archiving_desc' | translate }}
</label>
<input type="date" name="arch" />
</section>
<h3>{{ 'visibility.access' | translate }}</h3>
<section class="row">
<label for="password">Je</label>
<select name="password">
<option value="yes" selected>
{{ 'visibility.access_want_yes' | translate }}
</option>
<option value="no">
{{ 'visibility.access_want_no' | translate }}
</option>
</select>
<label for="alter-vote">
{{ 'visibility.access_protect' | translate }}
</label>
</section>
<h3>{{ 'admin.deletion' | translate }}</h3>
<label for="del"> {{ 'admin.deletion_desc' | translate }} </label>
<input class="btn btn--alert" type="submit" name="del" value="{{ 'admin.deletion_btn' | translate }}" />
<!-- Access link -->
<h2>{{ 'admin.link' | translate }}</h2>
<h3>{{ 'admin.link_admin' | translate }}</h3>
<label for="copy-link-admin">
{{ 'admin.link_admin_desc' | translate }}
https://framadate.org/urladmindusondage
</label>
<input class="btn btn--mini" type="submit" name="copy-link-admin" value="{{ 'admin.copy_link' | translate }}" />
<a href="#" class="next">{{ 'admin.link_admin_btn' | translate }}</a>
<h3>{{ 'admin.polled_people' | translate }}</h3>
<label for="copy-link">
{{ 'admin.polled_people_desc' | translate }}
{{ config.urlPublic }}</label
>
<input class="btn btn--mini" type="submit" name="copy-link" value="{{ 'admin.copy_link' | translate }}" />
<a href="#" class="next">{{ 'admin.polled_people_btn' | translate }}</a>
<h3>{{ 'admin.email_links' | translate }}</h3>
<label for="mail">{{ 'admin.email_links_desc' | translate }}</label>
<input type="email" name="mail" />
<input class="btn btn--mini" type="submit" name="send-mail" value="{{ 'admin.email_links_btn' | translate }}" />
</form>
<p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"></p-confirmDialog>
<div>
<h1>
admin page to modify a poll
</h1>
<div class="well">
<h2>Anybody with this link can modify and delete the poll</h2>
<strong> token: {{ tokenForAdministration }} </strong>
coming soon
</div>
</div>

View File

@ -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);
}
);
}
}