Inicio page is offline

This commit is contained in:
Eudes Inácio
2021-09-21 06:09:41 +01:00
parent 7fdb16c272
commit 42ae5de817
15 changed files with 702 additions and 437 deletions
+1 -1
View File
@@ -47,7 +47,7 @@
<!-- {{ toDayEventStorage.eventsList | json}} -->
<ion-list>
<ion-item class="item-hover cursor-pointer" lines="none" *ngFor="let event of toDayEventStorage.eventsList"
<ion-item class="item-hover cursor-pointer" lines="none" *ngFor="let event of listToPresent"
(click)="goToEvent(event.EventId)"
>
<div class="d-flex content-{{loggeduser.Profile}}-{{event.CalendarName}}">
+158 -73
View File
@@ -12,10 +12,12 @@ import { EventDetailPage } from './event-detail/event-detail.page';
import { ProcessesService } from '../../services/processes.service';
import { DailyWorkTask } from '../../models/dailyworktask.model';
import { LoginUserRespose } from 'src/app/models/user.model';
import { ToDayEventStorage } from 'src/app/store/to-day-event-storage.service';
import { ToDayEventStorage } from 'src/app/store/to-day-event-storage.service';
import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
import { SqliteService } from 'src/app/services/sqlite.service';
import { synchro } from '../../services/socket/synchro.service';
@Component({
selector: 'app-events',
@@ -29,16 +31,16 @@ export class EventsPage implements OnInit {
months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
customDate = this.days[this.today.getDay()]+ ", " + this.today.getDate() +" de " + ( this.months[this.today.getMonth()]);
customDate = this.days[this.today.getDay()] + ", " + this.today.getDate() + " de " + (this.months[this.today.getMonth()]);
/* Setting appropriate greeting according to the time */
grettings = ["Bom dia", "Boa tarde", "Boa noite"];
greetting='';
greetting = '';
timeDate = this.today.getHours() + ":" + this.today.getMinutes();
/* Set segment variable */
segment:string;
public profile:string;
segment: string;
public profile: string;
currentEvent: any;
eventsList: Event[];
@@ -52,55 +54,65 @@ export class EventsPage implements OnInit {
combinedEvents: Event[];
customText = false;
totalEvent=0;
totalEvent = 0;
currentHoursMinutes: Date | string;
showLoader: boolean;
taskslist:DailyWorkTask[] = [];
expedientList:any;
hideSearchBtn: boolean=false;
taskslist: DailyWorkTask[] = [];
expedientList: any;
hideSearchBtn: boolean = false;
// shared data
toDayEventStorage = ToDayEventStorage
expedienteGdStore = ExpedienteGdStore
listToPresent
expedienteTaskPipe = new ExpedienteTaskPipe()
@Output() openExpedientListPage:EventEmitter<any> = new EventEmitter<any>();
@Output() openExpedientListPage: EventEmitter<any> = new EventEmitter<any>();
loggeduser: LoginUserRespose;
existingScreenOrientation: string;
synch = synchro
constructor(
private eventService: EventsService,
private router: Router,
private storageService:StorageService,
private storageService: StorageService,
public activatedRoute: ActivatedRoute,
private alertController: AlertService,
private authService: AuthService,
private processes:ProcessesService,
private processes: ProcessesService,
/* private gabineteService: GabineteDigitalPage, */
private modalController:ModalController,
private modalController: ModalController,
private screenOrientation: ScreenOrientation,
public platform: Platform,
) {
this.existingScreenOrientation = this.screenOrientation.type;
console.log(this.existingScreenOrientation);
private sqliteservice: SqliteService,
) {
this.existingScreenOrientation = this.screenOrientation.type;
console.log(this.existingScreenOrientation);
this.loggeduser = authService.ValidatedUser;
this.loggeduser = authService.ValidatedUser;
this.prEventList = null;
this.prEventList = null;
this.platform.resize.subscribe(async () => {
//console.log('Resize event detected');
// console.log('Resize event detected');
this.platform.resize.subscribe(async () => {
//console.log('Resize event detected');
// console.log('Resize event detected');
});
});
try {
this.sqliteservice.databaseConn();
} catch (error) {
console.log("Error creating local database: ", error)
}
}
ngOnInit() {
this.segment = "Combinada";
@@ -109,18 +121,20 @@ export class EventsPage implements OnInit {
this.showGreeting();
this.router.events.forEach((event) => {
if(event instanceof NavigationEnd && event.url == '/home/events') {
if (event instanceof NavigationEnd && event.url == '/home/events') {
this.RefreshEvents();
this.LoadList();
}
});
this.hideSearch();
this.getEventsFromLocalDb();
//this.checkScreenOrientation();
}
hideSearch(){
if(this.router.url == '/home/events'){
hideSearch() {
if (this.router.url == '/home/events') {
this.hideSearchBtn = true;
}
}
@@ -136,28 +150,28 @@ export class EventsPage implements OnInit {
}
// Lock to portrait
lockToPortrait(){
lockToPortrait() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
console.log('set');
}
// Lock to landscape
lockToLandscape(){
// Lock to landscape
lockToLandscape() {
this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
}
// Unlock screen orientation
unlockScreenOrientation(){
// Unlock screen orientation
unlockScreenOrientation() {
this.screenOrientation.unlock();
}
checkScreenOrientation(){
if( window.innerWidth < 701) {
checkScreenOrientation() {
if (window.innerWidth < 701) {
this.lockToPortrait();
console.log('was here');
}
else{
else {
this.unlockScreenOrientation();
}
}
@@ -168,20 +182,24 @@ export class EventsPage implements OnInit {
let date = new Date();
date.setMonth(date.getMonth() + 1);
let start = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+ ":"+date.getSeconds();
let end = date.getFullYear()+"-"+ date.getMonth()+"-"+date.getDate()+" 23:59:59";
let start = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
let end = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate() + " 23:59:59";
if(this.loggeduser.Profile == 'MDGPR') {
if (this.loggeduser.Profile == 'MDGPR') {
let mdOficialEvents = await this.eventService.getAllMdOficialEvents(start, end).toPromise();
let mdPessoalEvents = await this.eventService.getAllMdPessoalEvents(start, end).toPromise();
const list = mdOficialEvents.concat(mdPessoalEvents);
console.log("getAllMdOficialPessoalEvents", list)
this.SqliteAddEvent(list);
this.listToPresent = this.toDayEventStorage.eventsList
this.toDayEventStorage.reset(list)
if(this.toDayEventStorage.eventsList.length > 0){
if (this.toDayEventStorage.eventsList.length > 0) {
this.currentEvent = this.toDayEventStorage.eventsList[0].Subject;
this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate;
}
@@ -192,18 +210,20 @@ export class EventsPage implements OnInit {
}
else if (this.loggeduser.Profile == 'PR') {
let prOficialEvents= await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let prPessoalEvents= await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
let prOficialEvents = await this.eventService.getAllPrOficialEvents(start, end).toPromise();
let prPessoalEvents = await this.eventService.getAllPrPessoalEvents(start, end).toPromise();
const list = prOficialEvents.concat(prPessoalEvents);
console.log("getAllPrOficialPessoalEvents", list)
this.SqliteAddEvent(list);
this.toDayEventStorage.reset(list)
if(this.toDayEventStorage.eventsList.length > 0) {
if (this.toDayEventStorage.eventsList.length > 0) {
this.currentEvent = this.toDayEventStorage.eventsList[0].Subject;
this.currentHoursMinutes = this.toDayEventStorage.eventsList[0].StartDate;
}
this.listToPresent = this.toDayEventStorage.eventsList;
this.totalEvent = this.toDayEventStorage.eventsList.length;
this.showLoader = false;
@@ -279,48 +299,110 @@ export class EventsPage implements OnInit {
break;
} */
}
SqliteAddEvent(list) {
list.forEach((event) => {
let data = {
EventId: event.EventId,
HasAttachments: event.HasAttachments,
Subject: event.Subject,
Location: event.Location,
CalendarId: event.CalendarId,
CalendarName: event.CalendarName,
StartDate: event.StartDate,
EndDate: event.EndDate,
EventType: "",
Attendees: "",
IsMeeting: "",
IsRecurring: "",
IsAllDayEvent: event.IsAllDayEvent,
AppointmentState: "",
TimeZone: "",
Organizer: "",
Category: "",
EventRecurrence: "",
Attachments: "",
Body: ""
}
showGreeting(){
if(this.today.getHours() >= 6 && this.today.getHours() < 12){
if(!event.Organizer){
this.sqliteservice.addEvent(data);
console.log("Events page add event sqllite")
}
})
}
getEventsFromLocalDb() {
synchro.registerCallback('Online', () => {
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == '/home/events') {
this.RefreshEvents();
this.LoadList();
}
});
console.log('Onlineee')
})
synchro.registerCallback('Offline', () => {
this.platform.ready().then(() => {
this.sqliteservice.getAllEvents().then((event) => {
this.listToPresent = event
this.totalEvent = this.listToPresent.length
this.currentEvent = this.listToPresent[0].Subject
this.currentHoursMinutes = this.listToPresent[0].StartDate
console.log("All events from local,", event)
})
console.log('Offlineee')
})
})
}
showGreeting() {
if (this.today.getHours() >= 6 && this.today.getHours() < 12) {
this.greetting = this.grettings[0];
}
else if(this.today.getHours() >= 12 && this.today.getHours() < 18){
else if (this.today.getHours() >= 12 && this.today.getHours() < 18) {
this.greetting = this.grettings[1];
}
else /* if(this.today.getHours() < 6 && this.today.getHours() >= 18) */{
else /* if(this.today.getHours() < 6 && this.today.getHours() >= 18) */ {
this.greetting = this.grettings[2];
}
}
gotTo(){
gotTo() {
this.router.navigate(['/home/events']);
}
changeProfile(){
if(this.profile == "mdgpr"){
changeProfile() {
if (this.profile == "mdgpr") {
console.log('pr');
this.profile ="pr";
this.profile = "pr";
this.RefreshEvents();
}
else{
else {
console.log('mdgpr');
this.profile ="mdgpr";
this.profile = "mdgpr";
this.RefreshEvents();
}
}
logout()
{
logout() {
this.authService.ValidatedUser.BasicAuthKey = "";
this.router.navigate(['/home/login']);
}
async openEventDetail1(id:any){
async openEventDetail1(id: any) {
console.log(id);
const modal = await this.modalController.create({
component: EventDetailPage,
componentProps: {
componentProps: {
eventId: id,
},
cssClass: 'event-detail',
@@ -335,52 +417,55 @@ export class EventsPage implements OnInit {
this.processes.GetTaskListExpediente(false).subscribe(result => {
console.log("Expediente", result);
const ExpedienteTask = result.map( e=> this.expedienteTaskPipe.transform(e))
const ExpedienteTask = result.map(e => this.expedienteTaskPipe.transform(e))
this.expedienteGdStore.reset(ExpedienteTask)
});
}
sortArrayISODate(myArray: any){
return myArray.sort(function(a, b) {
sortArrayISODate(myArray: any) {
return myArray.sort(function (a, b) {
return (a.CreateDate < b.CreateDate) ? -1 : ((a.CreateDate > b.CreateDate) ? 1 : 0);
});
}
goToEvent(eventId:any){
goToEvent(eventId: any) {
this.router.navigate(['/home/events', eventId, 'events']);
}
goToExpediente(SerialNumber:any) {
if(this.loggeduser.Profile == 'MDGPR'){
goToExpediente(SerialNumber: any) {
if (this.loggeduser.Profile == 'MDGPR') {
this.router.navigate(['/home/events/expediente', SerialNumber, 'events']);
}
else if(this.loggeduser.Profile == 'PR'){
else if (this.loggeduser.Profile == 'PR') {
this.router.navigate(['/home/events/expedientes-pr', SerialNumber, 'events']);
}
}
viewExpedientListPage(){
if(this.loggeduser.Profile == 'MDGPR'){
if( window.innerWidth < 801){
viewExpedientListPage() {
if (this.loggeduser.Profile == 'MDGPR') {
if (window.innerWidth < 801) {
this.router.navigate(['/home/gabinete-digital/expediente']);
}
else{
let navigationExtras: NavigationExtras = { queryParams: {"expedientes": true,} };
else {
let navigationExtras: NavigationExtras = { queryParams: { "expedientes": true, } };
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
}
else if(this.loggeduser.Profile == 'PR'){
if( window.innerWidth < 801){
else if (this.loggeduser.Profile == 'PR') {
if (window.innerWidth < 801) {
this.router.navigate(['/home/gabinete-digital/expedientes-pr']);
}
else{
let navigationExtras: NavigationExtras = { queryParams: {"expedientes-pr": true,} };
else {
let navigationExtras: NavigationExtras = { queryParams: { "expedientes-pr": true, } };
this.router.navigate(['/home/gabinete-digital'], navigationExtras);
}
}
}
}