mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
modalReviewd
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
import { CustomImageCachePage } from './custom-image-cache.page';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: CustomImageCachePage
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class CustomImageCachePageRoutingModule {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { CustomImageCachePageRoutingModule } from './custom-image-cache-routing.module';
|
||||
|
||||
import { CustomImageCachePage } from './custom-image-cache.page';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
FormsModule,
|
||||
IonicModule,
|
||||
CustomImageCachePageRoutingModule
|
||||
],
|
||||
exports: [CustomImageCachePage],
|
||||
declarations: [CustomImageCachePage]
|
||||
})
|
||||
export class CustomImageCachePageModule {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<img [src]="_src" *ngIf="_src !=''; else loading;">
|
||||
|
||||
<ng-template #loading>
|
||||
<ion-spinner></ion-spinner>
|
||||
</ng-template>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { IonicModule } from '@ionic/angular';
|
||||
|
||||
import { CustomImageCachePage } from './custom-image-cache.page';
|
||||
|
||||
describe('CustomImageCachePage', () => {
|
||||
let component: CustomImageCachePage;
|
||||
let fixture: ComponentFixture<CustomImageCachePage>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CustomImageCachePage ],
|
||||
imports: [IonicModule.forRoot()]
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(CustomImageCachePage);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Directory, Filesystem } from '@capacitor/filesystem';
|
||||
// import { readFile } from 'fs';
|
||||
|
||||
|
||||
|
||||
const CACHE_FOLDER = 'CACHED-IMG'
|
||||
|
||||
@Component({
|
||||
selector: 'app-custom-image-cache',
|
||||
templateUrl: './custom-image-cache.page.html',
|
||||
styleUrls: ['./custom-image-cache.page.scss'],
|
||||
})
|
||||
export class CustomImageCachePage implements OnInit {
|
||||
|
||||
_src ="";
|
||||
@Input () spinner = false
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
constructor() { }
|
||||
|
||||
@Input()
|
||||
set src(imageUrl: string){
|
||||
console.log('SET SOURCE', imageUrl)
|
||||
|
||||
const imageName = imageUrl.split('/').pop()
|
||||
const fileType = imageName.split('.').pop()
|
||||
|
||||
Filesystem.readFile({
|
||||
directory: Directory.Cache,
|
||||
path: `${CACHE_FOLDER}/${imageName}`}).then(readFile =>{
|
||||
console.log('LOCAL FILE: ', readFile)
|
||||
// set to SRC
|
||||
this._src = `data:image/${fileType};base64ToFile, ${readFile.data}`
|
||||
}).catch(async e =>{
|
||||
await this.storedImage(imageUrl, imageName)
|
||||
})
|
||||
Filesystem.readFile({
|
||||
directory: Directory.Cache,
|
||||
path: `${CACHE_FOLDER}/${imageName}`
|
||||
}).then(readFile =>{
|
||||
this._src = `data:image/${fileType};base64ToFile, ${readFile.data}`
|
||||
})
|
||||
|
||||
}
|
||||
async storedImage(url, path){
|
||||
const response = await fetch(`http://api-cors-proxy-devdactic.herokuapp.com/${url}`)
|
||||
const blob = await response.blob()
|
||||
|
||||
const base64Data = await this.convertBlobToBase64(blob) as string;
|
||||
const savedFile = await Filesystem.writeFile({
|
||||
path: `${CACHE_FOLDER}/${path}`,
|
||||
data: base64Data,
|
||||
directory: Directory.Cache
|
||||
})
|
||||
return savedFile
|
||||
}
|
||||
|
||||
convertBlobToBase64(blob: Blob){
|
||||
return new Promise((resolve, reject) =>{
|
||||
const reader = new FileReader;
|
||||
reader.onerror = reject;
|
||||
reader.onload = () => {
|
||||
resolve(reader.result)
|
||||
}
|
||||
reader.readAsDataURL(blob)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, OnInit } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { AuthService } from '../services/auth.service';
|
||||
@@ -6,20 +6,27 @@ import { LoginUserRespose } from '../models/user.model';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators'
|
||||
import { Publication } from '../models/publication';
|
||||
import { getUrl } from 'ionicons/dist/types/components/icon/utils';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PublicationsService {
|
||||
export class PublicationsService {
|
||||
|
||||
|
||||
|
||||
authheader = {};
|
||||
loggeduser: LoginUserRespose;
|
||||
headers: HttpHeaders;
|
||||
|
||||
constructor(private http: HttpClient, user: AuthService) {
|
||||
constructor(private http: HttpClient, user: AuthService,
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.loggeduser = user.ValidatedUser;
|
||||
this.headers = new HttpHeaders();
|
||||
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
|
||||
|
||||
}
|
||||
|
||||
GetPublicationFolderList(){
|
||||
@@ -77,6 +84,7 @@ export class PublicationsService {
|
||||
return this.http.delete<any>(`${geturl}`, options);
|
||||
}
|
||||
|
||||
//this worker obervable goes to ForkJoin as a second api call
|
||||
GetPublications(id:any){
|
||||
const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts';
|
||||
let params = new HttpParams();
|
||||
@@ -90,6 +98,20 @@ export class PublicationsService {
|
||||
return this.http.get<Publication[]>(`${geturl}`, options)
|
||||
}
|
||||
|
||||
// this one too,goes to observable as a first api call
|
||||
GetIdsPublicationsImages(id:any){
|
||||
const geturl = environment.apiURL + 'presidentialActions/'+ id +'/posts/ids';
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("folderId", id);
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
return this.http.get<number[]>(`${geturl}`, options)
|
||||
}
|
||||
|
||||
GetPublicationById( publicationId:any){
|
||||
const geturl = environment.apiURL + 'presidentialActions/posts/'+ publicationId;
|
||||
let params = new HttpParams();
|
||||
@@ -103,6 +125,60 @@ export class PublicationsService {
|
||||
return this.http.get<any>(`${geturl}`, options);
|
||||
}
|
||||
|
||||
// my own tries
|
||||
|
||||
GetPublicationByIdNext( publicationId:any){
|
||||
let geturl = environment.apiURL + 'presidentialActions/'+ publicationId + '/posts/ids';
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("folderId", publicationId);
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
/* params: params */
|
||||
};
|
||||
|
||||
const imageLoads = !!(+localStorage.getItem('loadedimage'))
|
||||
if(imageLoads){
|
||||
return true
|
||||
}else{
|
||||
const navigation = this.router.getCurrentNavigation()
|
||||
console.log('nav:', navigation)
|
||||
|
||||
if(navigation){
|
||||
geturl = navigation.extractedUrl.toString()
|
||||
}
|
||||
|
||||
this.router.navigate([URL], {queryParams: {returnto: geturl}})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GetIdsPublicationNext(id:any){
|
||||
let geturl = environment.apiURL + 'presidentialActions/posts/' + id;
|
||||
let params = new HttpParams();
|
||||
|
||||
params = params.set("id", id);
|
||||
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
};
|
||||
|
||||
var search = this.http.get<any>(`${geturl}`, options).subscribe(
|
||||
res => {
|
||||
res.this.activatedRoute.snapshot.queryParams.get('returnto') || '/posts'
|
||||
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
return search
|
||||
|
||||
}
|
||||
|
||||
//my last tries
|
||||
|
||||
CreatePublication(folderId:any,body:any){
|
||||
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts';
|
||||
let params = new HttpParams();
|
||||
|
||||
Reference in New Issue
Block a user