mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
fix
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { HolderService } from './holder.service';
|
||||
|
||||
describe('HolderService', () => {
|
||||
let service: HolderService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(HolderService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class HolderService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PublicationHolderService } from './publication-holder.service';
|
||||
|
||||
describe('PublicationHolderService', () => {
|
||||
let service: PublicationHolderService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(PublicationHolderService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { PublicationFormMV } from 'src/app/shared/publication/upload/upload-streaming.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class PublicationHolderService {
|
||||
|
||||
count = 0
|
||||
PublicationFormMV: {
|
||||
id: string,
|
||||
percentage: number,
|
||||
retry: boolean,
|
||||
retryFunction: Function
|
||||
}[] = []
|
||||
|
||||
constructor() {
|
||||
|
||||
window['upload-header-set-percentage'] = (id: string, percentage: number) => {
|
||||
this.PublicationFormMV = this.PublicationFormMV.map((e)=> {
|
||||
if(e.id == id) {
|
||||
console.log("percentage", percentage)
|
||||
e.percentage = percentage
|
||||
}
|
||||
return e
|
||||
})
|
||||
|
||||
|
||||
this.uploadPercentage()
|
||||
}
|
||||
|
||||
window['upload-header-set-add'] = (id: string, percentage: number, save: Function) => {
|
||||
this.PublicationFormMV.push({id, percentage, retry: false, retryFunction: save})
|
||||
this.uploadPercentage()
|
||||
}
|
||||
|
||||
|
||||
window['upload-header-set-remove'] = (id: string) => {
|
||||
this.remove(id)
|
||||
}
|
||||
|
||||
|
||||
window['upload-header-set-retry'] = (id: string) => {
|
||||
|
||||
this.PublicationFormMV = this.PublicationFormMV.map((e)=> {
|
||||
if(e.id == id) {
|
||||
e.retry = true
|
||||
}
|
||||
return e
|
||||
})
|
||||
|
||||
this.uploadPercentage()
|
||||
}
|
||||
|
||||
window['upload-header-remove-retry'] = (id: string) => {
|
||||
this.uploadPercentage()
|
||||
|
||||
this.PublicationFormMV = this.PublicationFormMV.map((e)=> {
|
||||
if(e.id == id) {
|
||||
e.retry = false
|
||||
}
|
||||
return e
|
||||
})
|
||||
|
||||
|
||||
this.uploadPercentage()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
remove(id: string) {
|
||||
this.PublicationFormMV = this.PublicationFormMV.filter((e)=> e.id != id)
|
||||
this.uploadPercentage()
|
||||
}
|
||||
|
||||
hasPublication() {
|
||||
return this.PublicationFormMV.length >= 1
|
||||
}
|
||||
|
||||
|
||||
uploadPercentage = () => {
|
||||
|
||||
const percentageArray = this.PublicationFormMV.map((e) => e.percentage)
|
||||
|
||||
// Check if the array is not empty
|
||||
if (percentageArray.length === 0) {
|
||||
this.count = 0
|
||||
} else {
|
||||
let sum = percentageArray.reduce((acc, percentage) => acc + percentage, 0);
|
||||
|
||||
// Calculate the average percentage
|
||||
let averagePercentage = sum / percentageArray.length;
|
||||
|
||||
this.count = Math.ceil(averagePercentage)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user