1-Improved project structure. 2-Added new pages. 3-Prepared the environment to consume APIS. 4-Added Axios to the project. 5-Added get methods.

This commit is contained in:
Tiago Kayaya
2020-08-18 23:32:12 +01:00
parent 6e273e6eb8
commit 63f7b08091
23 changed files with 756 additions and 34 deletions
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { EventsService } from './events.service';
describe('EventsService', () => {
let service: EventsService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(EventsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+128
View File
@@ -0,0 +1,128 @@
import { Injectable } from '@angular/core';
import { Event } from '../models/event.model';
import axios from 'axios'
@Injectable({
providedIn: 'root'
})
export class EventsService {
/* Set events */
private eventos: Event = {
EventId: '1',
Subject: 'Reunião do Conselho de Ministros',
Body: null,
Location: 'Luanda, Palácio presidencial',
CalendarId: '',
CalendarName: 'poo',
StartDate: '10:30',
EndDate: '11:00',
EventType: '',
RequiredAttendees: null,
OptionalAttendees: null,
HasAttachments: false,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Categories: null,
Attachments: null,
};
private events: Event[] = [
{
EventId: '1',
Subject: 'Reunião do Conselho de Ministros',
Body: null,
Location: 'Luanda, Palácio presidencial',
CalendarId: '',
CalendarName: 'poo',
StartDate: '10:30',
EndDate: '11:00',
EventType: '',
RequiredAttendees: null,
OptionalAttendees: null,
HasAttachments: false,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Categories: null,
Attachments: null,
},
{
EventId: '2',
Subject: 'Conference call Particular',
Body: null,
Location: 'Luanda, Palácio presidencial',
CalendarId: '',
CalendarName: 'poo',
StartDate: '10:30',
EndDate: '11:00',
EventType: '',
RequiredAttendees: null,
OptionalAttendees: null,
HasAttachments: false,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
Categories: null,
Attachments: null,
}
];
constructor() { }
getAllEvents(){
/* Return a copy of the events in my array */
console.log("All eventes loaded");
const options = {
headers: {'Authorization': 'Basic cGF1bG8ucGludG86dGFidGVzdGVAMDA2'}
};
const url = 'http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/api/calendar/GetEvents?StartDate=2020-08-14 00:00:00&EndDate=2020-08-19 23:59:00&CalendarName=Pessoal';
axios.get(url, options)
.then((response) => {
console.log(response.data[0].EventId);
/* console.log(response.data[0].Subject);
console.log(response.status);
console.log(response.statusText);
console.log(response.headers); */
console.log(response.data[0]);
console.log(this.eventos);
this.eventos = response.data[0];
console.log(this.events[0].CalendarName);
console.log(this.events[0].CalendarName);
console.log("THEN");
console.log([this.eventos.CalendarName])
/* return [this.events[0]]; */
console.log(response.data);
console.log(this.eventos);
console.log(this.events[0].CalendarName);
this.events = response.data;
/* return [...this.events]; */
});
return [...this.events];
/* return [...this.events]; */
}
getEvent(eventId: string){
return {
/* The find() function looks for an event in a array and return true if found */
...this.events.find(event => {
/* Compare if the event found is the same as the event passed in as parameter */
return event.EventId === eventId;
})
};
}
}