mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
send stack of votes button linked to api
This commit is contained in:
parent
3abef619c8
commit
7a83beae8e
@ -2,9 +2,12 @@ export class Vote {
|
||||
public choice_id: number = 0;
|
||||
public value: string = ''; // valeur de réponse
|
||||
|
||||
constructor(choice_id?) {
|
||||
constructor(choice_id?, value?) {
|
||||
if (choice_id) {
|
||||
this.choice_id = choice_id;
|
||||
}
|
||||
if (value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ToastService } from './toast.service';
|
||||
import { LoaderService } from './loader.service';
|
||||
import { Stack } from '../models/stack.model';
|
||||
|
||||
const apiVersion = environment.api.versionToUse;
|
||||
const currentApiRoutes = environment.api.version[apiVersion];
|
||||
@ -30,8 +31,11 @@ export class ApiService {
|
||||
private readonly usersEndpoint = apiEndpoints.users.name;
|
||||
private readonly usersPollsEndpoint = apiEndpoints.users.polls.name;
|
||||
private readonly usersPollsSendEmailEndpoint = apiEndpoints.users.polls.sendEmail.name;
|
||||
private baseHref: string;
|
||||
|
||||
constructor(private http: HttpClient, private loader: LoaderService, private toastService: ToastService) {
|
||||
this.baseHref = apiBaseHref;
|
||||
|
||||
this.axiosInstance = axios.create({ baseURL: apiBaseHref });
|
||||
this.axiosInstance.defaults.timeout = 2500;
|
||||
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
|
||||
@ -91,9 +95,9 @@ export class ApiService {
|
||||
public async createPoll(poll: Poll): Promise<Subscription> {
|
||||
// this.loader.setStatus(true);
|
||||
console.log('createPoll config', poll);
|
||||
const baseHref = this.useDevLocalServer ? 'http://localhost:8000' : apiBaseHref;
|
||||
|
||||
return this.axiosInstance.post(
|
||||
`${baseHref}${currentApiRoutes['api_new_poll']}`,
|
||||
`${this.baseHref}${currentApiRoutes['api_new_poll']}`,
|
||||
poll,
|
||||
ApiService.makeHeaders()
|
||||
);
|
||||
@ -108,6 +112,24 @@ export class ApiService {
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* send a new vote stack
|
||||
* @param poll
|
||||
* @param vote_stack
|
||||
*/
|
||||
public async sendVoteStackOfPoll(poll: Poll, vote_stack: Stack) {
|
||||
// api_new_vote_stack POST ANY ANY /api/v1/poll/{id}/answer
|
||||
|
||||
console.log('vote_stack', vote_stack);
|
||||
console.log('this.baseHref', this.baseHref);
|
||||
|
||||
try {
|
||||
return await this.axiosInstance.post(`${this.pollsEndpoint}/${poll.custom_url}/answer`, vote_stack);
|
||||
} catch (error) {
|
||||
ApiService.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
//////////
|
||||
// READ //
|
||||
|
||||
|
@ -6,6 +6,7 @@ import { Theme } from '../enums/theme.enum';
|
||||
import { Stack } from '../models/stack.model';
|
||||
import { Choice } from '../models/choice.model';
|
||||
import { Vote } from '../models/vote.model';
|
||||
import { environment } from '../../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -27,7 +28,11 @@ export class StorageService {
|
||||
this.vote_stack.votes = [];
|
||||
|
||||
for (let choice of choices_list) {
|
||||
this.vote_stack.votes.push(new Vote(choice.id));
|
||||
if (environment.autofill) {
|
||||
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
|
||||
} else {
|
||||
this.vote_stack.votes.push(new Vote(choice.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import { DateService } from '../../core/services/date.service';
|
||||
import { PollUtilities } from '../old-stuff/config/PollUtilities';
|
||||
import { Comment } from '../../core/models/comment.model';
|
||||
import { StorageService } from '../../core/services/storage.service';
|
||||
import { ApiService } from '../../core/services/api.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-consultation',
|
||||
@ -35,6 +36,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
||||
private utils: PollUtilities,
|
||||
private _Activatedroute: ActivatedRoute,
|
||||
public storageService: StorageService,
|
||||
public api: ApiService,
|
||||
public pollService: PollService,
|
||||
public dateService: DateService,
|
||||
private modalService: ModalService
|
||||
@ -72,12 +74,16 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
updateVote(myVoteStack: boolean) {
|
||||
updateVote() {
|
||||
alert('TODO');
|
||||
}
|
||||
|
||||
addVoteStack() {
|
||||
alert('TODO');
|
||||
this.api.sendVoteStackOfPoll(this.poll, this.storageService.vote_stack).then((resp) => {
|
||||
console.log('resp', resp);
|
||||
|
||||
this.api.getPollBySlug(this.poll.custom_url);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ const apiV1 = {
|
||||
|
||||
export const environment = {
|
||||
production: true,
|
||||
autofill: true,
|
||||
appTitle: 'FramaDate Funky',
|
||||
appVersion: '2.1.0',
|
||||
appLogo: 'assets/img/logo.png',
|
||||
|
@ -10,12 +10,14 @@ const apiV1 = {
|
||||
baseHref: 'http://localhost:8000/api/v1',
|
||||
api_new_poll: '/poll/',
|
||||
api_get_poll: '/poll/{id}',
|
||||
api_new_vote_stack: '/poll/{id}/answer',
|
||||
'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}',
|
||||
'app.swagger': '/api/doc.json',
|
||||
};
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
autofill: true,
|
||||
appTitle: 'FramaDate Funky',
|
||||
appVersion: '2.1.0',
|
||||
appLogo: 'assets/img/logo.png',
|
||||
|
Loading…
Reference in New Issue
Block a user