mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
Add loader to publication post
This commit is contained in:
@@ -58,7 +58,7 @@ export class PublicationFileGetByDocumentIdService {
|
||||
}
|
||||
}
|
||||
|
||||
for (const file of serverFiles) {
|
||||
for (const file of serverFiles.data || []) {
|
||||
const findLocally = await this.local.findOne({ name: file.name });
|
||||
|
||||
if (findLocally.isOk() && findLocally.value == null) {
|
||||
@@ -81,7 +81,7 @@ export class PublicationFileGetByDocumentIdService {
|
||||
}
|
||||
|
||||
for (const localFile of localResult.value) {
|
||||
const found = httpResult.value.data.filter((e) => e.name === localFile.name);
|
||||
const found = httpResult.value.data.data.filter((e) => e.name === localFile.name);
|
||||
if (found.length === 0 && localFile.name) {
|
||||
remove.push(localFile);
|
||||
await this.local.delete(localFile.id);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { IPublicationDocument, PublicationDocumentEntitySchema } from '../entity
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
import { MessageUpdateInput } from '../../chat/usecase/message/message-update-by-id-use-case.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { PublicationFileLocalRepositoryService } from 'src/app/module/actions/data/repository/publication-file-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -11,15 +12,21 @@ import { Logger } from 'src/app/services/logger/main/service';
|
||||
export class PublicationFilesDeleteByPathUseCaseService {
|
||||
|
||||
constructor(
|
||||
private remote: PublicationFileRepositoryService
|
||||
private remote: PublicationFileRepositoryService,
|
||||
private local: PublicationFileLocalRepositoryService
|
||||
) { }
|
||||
|
||||
execute(file: IPublicationDocument) {
|
||||
async execute(file: IPublicationDocument) {
|
||||
|
||||
const validation = zodSafeValidation<MessageUpdateInput>(PublicationDocumentEntitySchema, file)
|
||||
|
||||
if(validation.isOk()) {
|
||||
|
||||
const result = await this.local.findOne({ path: file.path })
|
||||
if(result.isOk()) {
|
||||
await this.local.delete(result.value.id);
|
||||
}
|
||||
|
||||
} else {
|
||||
Logger.error('failed to update message, validation failed', {
|
||||
zodErrorList: validation.error.errors,
|
||||
|
||||
@@ -12,11 +12,15 @@ import { TracingType } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
})
|
||||
export class HttpService {
|
||||
|
||||
pendingRequests = new Set<string>();
|
||||
private responseSubject = new BehaviorSubject<Result<HttpResult<any>, HttpErrorResponse>>(null);
|
||||
|
||||
constructor(private http: HttpClient) { }
|
||||
|
||||
private async handleRequest<T>(fux: Function, tracing?: TracingType, url?: string, method?: string): Promise<Result<HttpResult<T>, HttpErrorResponse>> {
|
||||
const requestKey = `${method}:${url.replace(":", "")}`;
|
||||
this.pendingRequests.add(requestKey);
|
||||
|
||||
try {
|
||||
var response = await fux(tracing) as HttpResponse<T>
|
||||
|
||||
@@ -24,7 +28,7 @@ export class HttpService {
|
||||
data: response.body,
|
||||
status: response.status,
|
||||
headers: response.headers,
|
||||
url: response.url || url,
|
||||
url: response.url || url,
|
||||
method: method || '',
|
||||
}
|
||||
this.responseSubject.next(ok(data))
|
||||
@@ -32,9 +36,22 @@ export class HttpService {
|
||||
} catch (e) {
|
||||
this.responseSubject.next(err(e))
|
||||
return err(e as HttpErrorResponse);
|
||||
} finally {
|
||||
this.pendingRequests.delete(requestKey);
|
||||
}
|
||||
}
|
||||
|
||||
hasPendingRequest(method: string, path: string): boolean {
|
||||
for (const key of this.pendingRequests) {
|
||||
const [reqMethod, reqUrl] = key.split(':');
|
||||
|
||||
if (reqMethod == method && reqUrl.toLowerCase().includes(path.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async post<T>(url: string, body: any, tracing?: TracingType): Promise<Result<HttpResult<T>, HttpErrorResponse>> {
|
||||
return await this.handleRequest<T>(async () => await this.http.post<T>(url, body, { observe: 'response' }).toPromise(), tracing, url, 'POST')
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ export class TokenInterceptor implements HttpInterceptor {
|
||||
}
|
||||
|
||||
return this.http
|
||||
.post<UserLoginOutputResponse>(`${environment.apiURL}Users/RefreshToken`, {
|
||||
.post<UserLoginOutputResponse>(`${environment.apiURLStage}Users/RefreshToken`, {
|
||||
authorization: SessionStore.user.Authorization,
|
||||
refreshToken: SessionStore.user.RefreshToken,
|
||||
channelId
|
||||
|
||||
+5
-2
@@ -4,6 +4,7 @@ import { PublicationListByProcessIdOutPut } from 'src/app/core/actions/use-case/
|
||||
import { ApiResponse } from 'src/app/infra/http/type';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { HttpService as HttpServiceInfra } from 'src/app/infra/http/http.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -13,7 +14,9 @@ export class PublicationFileRemoteRepositoryService {
|
||||
private baseUrl = `${environment.apiURLStage.slice(0, -1)}/PresidentialActions`; // Your base URL
|
||||
|
||||
constructor(
|
||||
private http: HttpService
|
||||
private http: HttpService,
|
||||
private httpServiceInfra: HttpServiceInfra,
|
||||
|
||||
) { }
|
||||
|
||||
async listByProcessId(processId: string) {
|
||||
@@ -22,6 +25,6 @@ export class PublicationFileRemoteRepositoryService {
|
||||
}
|
||||
|
||||
async FileListByDocumentId(input: PublicationFileGetByDocumentIdInput) {
|
||||
return await this.http.get<ApiResponse<PublicationFileGetByDocumentIdOutPut>>(`${this.baseUrl}/Posts/${input.documentId}/file`);
|
||||
return await this.httpServiceInfra.get<ApiResponse<PublicationFileGetByDocumentIdOutPut>>(`${this.baseUrl}/Posts/${input.documentId}/file`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,4 +28,20 @@ export class PublicationRemoteRepositoryService {
|
||||
async updatePublication(input: PublicationUpdateInputDto) {
|
||||
return await this.http.put<ApiResponse<PublicationUpdateInputDto>>(`${this.baseUrl}/${input.processId}/Posts/${input.documentId}`, input);
|
||||
}
|
||||
|
||||
|
||||
isUpdatingPublication(publicationId: string, processId: string): boolean {
|
||||
return this.http.hasPendingRequest(
|
||||
'PUT',
|
||||
`/PresidentialActions/${processId}/Posts/${publicationId}`
|
||||
);
|
||||
}
|
||||
|
||||
isFechingFilesPublication(publicationId: string): boolean {
|
||||
console.log('isFechingFilesPublication', `/PresidentialActions/Posts/${publicationId}/Posts`);
|
||||
return this.http.hasPendingRequest(
|
||||
'GET',
|
||||
`/PresidentialActions/Posts/${publicationId}/file`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ import { StopvideoService } from "src/app/services/stopvideo.service"
|
||||
import { App } from '@capacitor/app';
|
||||
import { ActiveTabService } from 'src/app/services/active-tab.service';
|
||||
import { PublicationHolderService } from 'src/app/services/publication/publication-holder.service'
|
||||
import { HttpService } from 'src/app/infra/http/http.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { PublicationRemoteRepositoryService } from 'src/app/module/actions/data/repository/publication-remote-repository.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-view-publications',
|
||||
@@ -74,7 +77,9 @@ export class ViewPublicationsPage implements OnInit {
|
||||
public stopvideoService: StopvideoService,
|
||||
public platform: Platform,
|
||||
public activeTabService: ActiveTabService,
|
||||
public PublicationHolderService: PublicationHolderService) {
|
||||
public PublicationHolderService: PublicationHolderService,
|
||||
private http: HttpService,
|
||||
private publicationRemoteRepository: PublicationRemoteRepositoryService) {
|
||||
|
||||
this.createPublicationList()
|
||||
|
||||
@@ -102,6 +107,9 @@ export class ViewPublicationsPage implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
isUploadingPublicationById(publicationId: string) {
|
||||
return this.publicationRemoteRepository.isUpdatingPublication(publicationId, this.folderId);
|
||||
}
|
||||
|
||||
onVisibilityChange = (e: boolean) => {
|
||||
if (!e) {
|
||||
|
||||
@@ -232,25 +232,25 @@ GetIdsPublicationNext(id:any){
|
||||
return this.http.post<any>(`${geturl}`, body, options)
|
||||
}
|
||||
|
||||
UpdatePublication(folderId:any,body:any){
|
||||
const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts';
|
||||
let params = new HttpParams();
|
||||
params = params.set("folderId", folderId);
|
||||
let options = {
|
||||
headers: this.headers,
|
||||
/* params: params */
|
||||
};
|
||||
// UpdatePublication(folderId:any,body:any){
|
||||
// const geturl = environment.apiURL + 'presidentialActions/'+folderId+'/posts';
|
||||
// let params = new HttpParams();
|
||||
// params = params.set("folderId", folderId);
|
||||
// let options = {
|
||||
// headers: this.headers,
|
||||
// /* params: params */
|
||||
// };
|
||||
|
||||
|
||||
|
||||
body.Files = body.Files.map( e => ({
|
||||
FileBase64: e.FileBase64,
|
||||
FileExtension: e.FileExtension,
|
||||
OriginalFileName: e.OriginalFileName || 'foto'
|
||||
}))
|
||||
// body.Files = body.Files.map( e => ({
|
||||
// FileBase64: e.FileBase64,
|
||||
// FileExtension: e.FileExtension,
|
||||
// OriginalFileName: e.OriginalFileName || 'foto'
|
||||
// }))
|
||||
|
||||
return this.http.put<any>(`${geturl}`, body, options)
|
||||
}
|
||||
// return this.http.put<any>(`${geturl}`, body, options)
|
||||
// }
|
||||
|
||||
DeletePublication(folderId:any,publicationId:any){
|
||||
var baseUrl = `${environment.apiURLStage.slice(0, -1)}/PresidentialActions`;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { v4 as uuidv4 } from 'uuid'
|
||||
import { Result } from 'neverthrow';
|
||||
import { IPublicationFormModelEntity } from '../new-publication/interface/interface';
|
||||
import { ModalController, Platform } from '@ionic/angular';
|
||||
import { PublicationRemoteRepositoryService } from 'src/app/module/actions/data/repository/publication-remote-repository.service';
|
||||
|
||||
enum ActionType {
|
||||
newRapid = "1",
|
||||
@@ -37,6 +38,7 @@ export class PublicationFromMvService {
|
||||
public PublicationFolderService: PublicationFolderService,
|
||||
public publicationFolderService: PublicationFolderService,
|
||||
private platform: Platform,
|
||||
private publicationRemoteRepository: PublicationRemoteRepositoryService
|
||||
) {}
|
||||
|
||||
clear() {
|
||||
@@ -121,7 +123,7 @@ export class PublicationFromMvService {
|
||||
|
||||
try {
|
||||
|
||||
const response = await this.publications.UpdatePublication(publication.ProcessId, publication).toPromise()
|
||||
await this.publicationRemoteRepository.updatePublication(publication);
|
||||
|
||||
if (this.form.cancel == false) {
|
||||
this.httpErroHandle.httpsSucessMessagge('Editar publicação')
|
||||
|
||||
@@ -56,7 +56,11 @@
|
||||
<div class="post-title">
|
||||
<ion-label>{{publication.title}}</ion-label>
|
||||
</div>
|
||||
<div class="post-data">{{publication.datePublication | date: 'dd-MM-yyyy HH:mm'}}</div>
|
||||
<div class="post-data">
|
||||
<p>
|
||||
{{publication.datePublication | date: 'dd-MM-yyyy HH:mm'}} <span *ngIf="isUploadingPublicationById(publication.documentId) || isFechingFilesPublicationById(publication.documentId)" class="loader"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="post-description">
|
||||
<app-show-more
|
||||
|
||||
@@ -199,7 +199,7 @@
|
||||
}
|
||||
.post-title-time{
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
.post-title{
|
||||
width: 60%;
|
||||
@@ -299,3 +299,19 @@ swiper-slide video {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.loader {
|
||||
display: inline-block;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 3px solid #ccc;
|
||||
border-top: 3px solid #c63427;
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ import { AskModalPage } from 'src/app/modals/ask-modal/ask-modal.page';
|
||||
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
|
||||
import { StopvideoService } from "src/app/services/stopvideo.service";
|
||||
import { PublicationHolderService } from 'src/app/services/publication/publication-holder.service'
|
||||
import { HttpService } from 'src/app/infra/http/http.service';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { PublicationRemoteRepositoryService } from 'src/app/module/actions/data/repository/publication-remote-repository.service';
|
||||
@Component({
|
||||
selector: 'app-view-publications',
|
||||
templateUrl: './view-publications.page.html',
|
||||
@@ -70,11 +73,19 @@ export class ViewPublicationsPage implements OnInit {
|
||||
public publicationFolderService: PublicationFolderService,
|
||||
public checkFileType: checkFileTypeService,
|
||||
public StopvideoService: StopvideoService,
|
||||
public PublicationHolderService: PublicationHolderService
|
||||
public PublicationHolderService: PublicationHolderService,
|
||||
private http: HttpService,
|
||||
private publicationRemoteRepository: PublicationRemoteRepositoryService
|
||||
) {
|
||||
this.createPublicationList()
|
||||
}
|
||||
|
||||
isUploadingPublicationById(publicationId: string) {
|
||||
return this.publicationRemoteRepository.isUpdatingPublication(publicationId, this.folderId);
|
||||
}
|
||||
isFechingFilesPublicationById(publicationId: string) {
|
||||
return this.publicationRemoteRepository.isFechingFilesPublication(publicationId);
|
||||
}
|
||||
|
||||
onVisibilityChange = (e: boolean) => {
|
||||
if(!e) {
|
||||
|
||||
@@ -170,7 +170,7 @@ video {
|
||||
}
|
||||
.post-title-time {
|
||||
width: 100%;
|
||||
overflow: auto;
|
||||
overflow: hidden;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.post-title {
|
||||
|
||||
@@ -40,7 +40,7 @@ export class SwiperPage implements OnInit {
|
||||
ngOnInit() {
|
||||
|
||||
this.local.find({documentId: this.documentId}).then(async e => {
|
||||
if(e.isOk() && e.value.length == 0) {
|
||||
if(e.isOk() && e.value.length == 0) { // has no files in local
|
||||
console.log('===============================================0')
|
||||
var result = await this.publicationFileGetByDocumentIdService.execute({
|
||||
documentId: this.documentId,
|
||||
@@ -51,11 +51,13 @@ export class SwiperPage implements OnInit {
|
||||
if(result.isOk()) {
|
||||
this.publicationList = result.value.added;
|
||||
this.makeLoad();
|
||||
this.updateSwiper();
|
||||
}
|
||||
} else if(e.isOk()) {
|
||||
} else if(e.isOk()) { // has files in local
|
||||
console.log('===============================================1')
|
||||
this.publicationList = e.value;
|
||||
this.makeLoad();
|
||||
this.updateSwiper();
|
||||
|
||||
var a = e.value.find(e => e.datePublication != this.datePublication)
|
||||
if(a) {
|
||||
@@ -69,6 +71,7 @@ export class SwiperPage implements OnInit {
|
||||
var newList = await this.local.find({documentId: this.documentId})
|
||||
if(newList.isOk()) {
|
||||
this.publicationList = newList.value;
|
||||
this.updateSwiper();
|
||||
}
|
||||
this.makeLoad();
|
||||
}
|
||||
@@ -188,6 +191,19 @@ export class SwiperPage implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
updateSwiper() {
|
||||
setTimeout(() => {
|
||||
if (this.swiperRef?.nativeElement?.swiper) {
|
||||
const swiper = this.swiperRef.nativeElement.swiper;
|
||||
swiper.update(); // Recalculate slides
|
||||
swiper.updateSlides(); // Rebuild slides
|
||||
swiper.updateProgress(); // Fix progress
|
||||
swiper.updateSize(); // Fix dimensions
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user