⚡ calls in administration page to delete things
This commit is contained in:
parent
ce4c3cb000
commit
bae3f19af2
|
@ -44,12 +44,14 @@ import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
|
||||||
import {ConfigService} from "./services/config.service";
|
import {ConfigService} from "./services/config.service";
|
||||||
import {PollService} from "./services/poll.service";
|
import {PollService} from "./services/poll.service";
|
||||||
import {ToastModule} from 'primeng/toast';
|
import {ToastModule} from 'primeng/toast';
|
||||||
import {MessageModule, MessageService} from "primeng";
|
import {ConfirmationService, MessageModule, MessageService} from "primeng";
|
||||||
import {PollDisplayComponent} from './pages/poll-display/poll-display.component';
|
import {PollDisplayComponent} from './pages/poll-display/poll-display.component';
|
||||||
import {VotingComponent} from './pages/voting/voting.component';
|
import {VotingComponent} from './pages/voting/voting.component';
|
||||||
import {VotingCommentComponent} from './pages/voting/voting-comment/voting-comment.component';
|
import {VotingCommentComponent} from './pages/voting/voting-comment/voting-comment.component';
|
||||||
import {ResettableInputDirective} from './ui/directives/resettable-input.directive';
|
import {ResettableInputDirective} from './ui/directives/resettable-input.directive';
|
||||||
import {ClipboardModule} from "ngx-clipboard";
|
import {ClipboardModule} from "ngx-clipboard";
|
||||||
|
import {ErasableInputComponent} from './ui/erasable-input/erasable-input.component';
|
||||||
|
import {ConfirmDialogModule} from 'primeng/confirmdialog';
|
||||||
|
|
||||||
export class MyMissingTranslationHandler implements MissingTranslationHandler {
|
export class MyMissingTranslationHandler implements MissingTranslationHandler {
|
||||||
handle(params: MissingTranslationHandlerParams) {
|
handle(params: MissingTranslationHandlerParams) {
|
||||||
|
@ -92,9 +94,11 @@ export function HttpLoaderFactory(http: HttpClient) {
|
||||||
VotingComponent,
|
VotingComponent,
|
||||||
VotingCommentComponent,
|
VotingCommentComponent,
|
||||||
ResettableInputDirective,
|
ResettableInputDirective,
|
||||||
|
ErasableInputComponent,
|
||||||
|
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
ConfirmDialogModule,
|
||||||
ClipboardModule,
|
ClipboardModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -119,7 +123,7 @@ export function HttpLoaderFactory(http: HttpClient) {
|
||||||
FormsModule,
|
FormsModule,
|
||||||
RouterModule.forRoot(Routes)
|
RouterModule.forRoot(Routes)
|
||||||
],
|
],
|
||||||
providers: [TranslateService, ConfigService, PollService, MessageService],
|
providers: [TranslateService, ConfigService, PollService, MessageService, ConfirmationService],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule {
|
export class AppModule {
|
||||||
|
|
|
@ -75,15 +75,25 @@
|
||||||
<label for="del-vote">
|
<label for="del-vote">
|
||||||
{{"admin.votes_deletion_desc"|translate}}
|
{{"admin.votes_deletion_desc"|translate}}
|
||||||
</label>
|
</label>
|
||||||
<input class="btn btn--alert btn--outline" type="submit"
|
<button class="btn btn--alert btn--outline"
|
||||||
name="del-vote" value="{{'admin.votes_deletion_btn'|translate}}">
|
(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>
|
<h3>{{"admin.comments_deletion_title"|translate}}</h3>
|
||||||
<label for="del-com">
|
<label for="del-com">
|
||||||
{{"admin.comments_deletion_desc"|translate}}
|
{{"admin.comments_deletion_desc"|translate}}
|
||||||
</label>
|
</label>
|
||||||
<input class="btn btn--alert btn--outline" type="submit"
|
|
||||||
name="del-com" value="{{'admin.comments_deletion_btn'|translate}}">
|
<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>
|
<h3>{{"admin.archiving_title"|translate}}</h3>
|
||||||
<section class="row">
|
<section class="row">
|
||||||
|
@ -129,7 +139,7 @@
|
||||||
<h3>{{"admin.polled_people"|translate}}</h3>
|
<h3>{{"admin.polled_people"|translate}}</h3>
|
||||||
<label for="copy-link">
|
<label for="copy-link">
|
||||||
{{"admin.polled_people_desc"|translate}}
|
{{"admin.polled_people_desc"|translate}}
|
||||||
https://framadate.org/urladmindusondage</label>
|
{{config.urlPublic}}</label>
|
||||||
<input class="btn btn--mini" type="submit" name="copy-link"
|
<input class="btn btn--mini" type="submit" name="copy-link"
|
||||||
value="{{'admin.copy_link'|translate}}">
|
value="{{'admin.copy_link'|translate}}">
|
||||||
<a href="#" class="next">{{"admin.polled_people_btn"|translate}}</a>
|
<a href="#" class="next">{{"admin.polled_people_btn"|translate}}</a>
|
||||||
|
@ -141,9 +151,27 @@
|
||||||
value="{{'admin.email_links_btn'|translate}}">
|
value="{{'admin.email_links_btn'|translate}}">
|
||||||
|
|
||||||
<section class="deletion">
|
<section class="deletion">
|
||||||
|
<h2>
|
||||||
|
|
||||||
{{"admin.deletion"|translate}}
|
{{"admin.deletion"|translate}}
|
||||||
|
</h2>
|
||||||
{{"admin.deletion_desc"|translate}}
|
{{"admin.deletion_desc"|translate}}
|
||||||
|
<button class="btn btn--danger" (click)="config.deletePoll()">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
<i class="fa fa-warning"></i>
|
||||||
{{"admin.deletion_btn"|translate}}
|
{{"admin.deletion_btn"|translate}}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn--danger" (click)="config.deleteComments()">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
<i class="fa fa-warning"></i>
|
||||||
|
{{"admin.comments_deletion_btn"|translate}}
|
||||||
|
</button>
|
||||||
|
<button class="btn btn--danger" (click)="config.deleteVotes()">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
<i class="fa fa-warning"></i>
|
||||||
|
{{"admin.votes_btn_votes"|translate}}
|
||||||
|
</button>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="links">
|
<section class="links">
|
||||||
|
@ -162,3 +190,4 @@
|
||||||
{{"admin.email_links_btn"|translate}}
|
{{"admin.email_links_btn"|translate}}
|
||||||
</section>
|
</section>
|
||||||
</form>
|
</form>
|
||||||
|
<p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"></p-confirmDialog>
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {ConfigService} from '../../services/config.service';
|
||||||
})
|
})
|
||||||
export class AdminComponent implements OnInit {
|
export class AdminComponent implements OnInit {
|
||||||
|
|
||||||
constructor() { }
|
constructor(private config : ConfigService) { }
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@
|
||||||
required="required"
|
required="required"
|
||||||
type="email"
|
type="email"
|
||||||
/>
|
/>
|
||||||
|
<framadate-erasable-input [(inputModel)]="config.myEmail"></framadate-erasable-input>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -2,7 +2,8 @@ import {Injectable} from '@angular/core';
|
||||||
import {PollConfig} from '../config/PollConfig';
|
import {PollConfig} from '../config/PollConfig';
|
||||||
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||||
import {environment} from "../../environments/environment";
|
import {environment} from "../../environments/environment";
|
||||||
import {MessageService} from 'primeng/api';
|
import {ConfirmationService, MessageService} from 'primeng/api';
|
||||||
|
import {Router} from "@angular/router";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
|
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
|
||||||
|
@ -18,7 +19,10 @@ export class ConfigService extends PollConfig {
|
||||||
|
|
||||||
|
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient,
|
||||||
private messageService: MessageService) {
|
private messageService: MessageService,
|
||||||
|
private router: Router,
|
||||||
|
private confirmationService: ConfirmationService,
|
||||||
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +195,10 @@ export class ConfigService extends PollConfig {
|
||||||
findLocalStorageData() {
|
findLocalStorageData() {
|
||||||
// TODO check if the person has a key to retrieve her polls
|
// TODO check if the person has a key to retrieve her polls
|
||||||
|
|
||||||
|
if (localStorage) {
|
||||||
|
console.log('localStorage', localStorage)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -280,28 +288,6 @@ export class ConfigService extends PollConfig {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* UPDATE
|
|
||||||
* /api/v1/poll/{id}/vote
|
|
||||||
* @param voteStack
|
|
||||||
*/
|
|
||||||
updatePoll(voteStack: any) {
|
|
||||||
this.http.put(
|
|
||||||
`${this.baseHref}/poll/${this.pollId}`,
|
|
||||||
voteStack,
|
|
||||||
this.makeHeaders()
|
|
||||||
)
|
|
||||||
.subscribe((res: any) => {
|
|
||||||
this.messageService.add({
|
|
||||||
severity: 'success',
|
|
||||||
summary: 'Sondage mis à jour',
|
|
||||||
});
|
|
||||||
this.myPolls = res;
|
|
||||||
}, (e) => {
|
|
||||||
this.handleError(e)
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST
|
* POST
|
||||||
|
@ -370,4 +356,104 @@ export class ConfigService extends PollConfig {
|
||||||
* administrator calls
|
* administrator calls
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
deleteComments() {
|
||||||
|
// prompt for confirmation
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Are you sure that you want to completely delete the comments of this poll (' + this.title + ') permanentely?',
|
||||||
|
accept: () => {
|
||||||
|
this.http.delete(
|
||||||
|
`${this.baseHref}/poll/${this.pollId}/comments`,
|
||||||
|
this.makeHeaders())
|
||||||
|
.subscribe((res: any) => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Commentaires bien supprimés',
|
||||||
|
detail: 'Commentaires du sondage "' + this.title + '" supprimé'
|
||||||
|
});
|
||||||
|
|
||||||
|
}, (e) => {
|
||||||
|
this.handleError(e)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteVotes() {
|
||||||
|
// prompt for confirmation
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Are you sure that you want to completely delete the votes of this poll (' + this.title + ') permanentely?',
|
||||||
|
accept: () => {
|
||||||
|
this.http.delete(
|
||||||
|
`${this.baseHref}/poll/${this.pollId}/votes`,
|
||||||
|
this.makeHeaders())
|
||||||
|
.subscribe((res: any) => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Votes bien supprimés',
|
||||||
|
detail: 'Votes du sondage "' + this.title + '" supprimé'
|
||||||
|
});
|
||||||
|
|
||||||
|
}, (e) => {
|
||||||
|
this.handleError(e)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deletePoll() {
|
||||||
|
if (!this.pollId) {
|
||||||
|
this.messageService.add({
|
||||||
|
summary: 'this poll is not administrable, it has no ID',
|
||||||
|
severity: 'warning'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let self = this;
|
||||||
|
// prompt for confirmation
|
||||||
|
this.confirmationService.confirm({
|
||||||
|
message: 'Are you sure that you want to completely delete this poll (' + self.title + ') and all is data permanentely?',
|
||||||
|
accept: () => {
|
||||||
|
this.http.delete(
|
||||||
|
`${this.baseHref}/poll/${this.pollId}`,
|
||||||
|
this.makeHeaders())
|
||||||
|
.subscribe((res: any) => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Sondage bien supprimé',
|
||||||
|
detail: 'sondage "' + this.title + '" supprimé'
|
||||||
|
});
|
||||||
|
|
||||||
|
this.router.navigate(['home']);
|
||||||
|
}, (e) => {
|
||||||
|
this.handleError(e)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UPDATE
|
||||||
|
* /api/v1/poll/{id}/vote
|
||||||
|
* @param voteStack
|
||||||
|
*/
|
||||||
|
updatePoll(voteStack: any) {
|
||||||
|
this.http.put(
|
||||||
|
`${this.baseHref}/poll/${this.pollId}`,
|
||||||
|
voteStack,
|
||||||
|
this.makeHeaders()
|
||||||
|
)
|
||||||
|
.subscribe((res: any) => {
|
||||||
|
this.messageService.add({
|
||||||
|
severity: 'success',
|
||||||
|
summary: 'Sondage mis à jour',
|
||||||
|
});
|
||||||
|
this.myPolls = res;
|
||||||
|
}, (e) => {
|
||||||
|
this.handleError(e)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
import {Directive} from '@angular/core';
|
import {Directive} from '@angular/core';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a button on an input which deletes its value
|
||||||
|
*/
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[framadateResettableInput]'
|
selector: '[framadateResettableInput]'
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<button class="erase" (click)="eraseInput()">
|
||||||
|
<i class="fa fa-times"></i>
|
||||||
|
</button>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ErasableInputComponent } from './erasable-input.component';
|
||||||
|
|
||||||
|
describe('ErasableInputComponent', () => {
|
||||||
|
let component: ErasableInputComponent;
|
||||||
|
let fixture: ComponentFixture<ErasableInputComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ErasableInputComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ErasableInputComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,31 @@
|
||||||
|
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'framadate-erasable-input',
|
||||||
|
templateUrl: './erasable-input.component.html',
|
||||||
|
styleUrls: ['./erasable-input.component.scss']
|
||||||
|
})
|
||||||
|
export class ErasableInputComponent implements OnInit {
|
||||||
|
|
||||||
|
@Output() inputModelChange = new EventEmitter();
|
||||||
|
|
||||||
|
@Input() get inputModel() {
|
||||||
|
return this.inputModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
set inputModel(val) {
|
||||||
|
// this.inputModel = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
}
|
||||||
|
|
||||||
|
eraseInput() {
|
||||||
|
this.inputModel = '';
|
||||||
|
this.inputModelChange.emit(this.inputModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue