diff --git a/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.html b/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.html index b39f2ca2..eaf7d854 100644 --- a/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.html @@ -26,36 +26,29 @@
-

{{ 'CREATE_CATALOG._new' | translate }}

-
-
-
- - -
- -
+

{{ 'CREATE_CATALOG._new' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+ +

{{ this.steps[currentStep] }}

+
- @if(showGeneral){ -

{{ 'CREATE_CATALOG._general' | translate }}

+ @if (currentStep === 0) {
{{ 'CREATE_
-
- + + + @if(currentStep === 1){ + + } +
diff --git a/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.ts b/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.ts index f80dab4b..ce758c38 100644 --- a/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-catalogs/create-catalog/create-catalog.component.ts @@ -23,6 +23,12 @@ export class CreateCatalogComponent implements OnInit { stepsElements:string[]=['general-info','summary']; stepsCircles:string[]=['general-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -98,6 +104,14 @@ export class CreateCatalogComponent implements OnInit { showFinish(){ this.finishDone=true; + this.setCatalogData(); + this.showGeneral=false; + this.showSummary=true; + this.selectStep('summary','summary-circle'); + this.showPreview=false; + } + + setCatalogData(){ if(this.generalForm.value.name!=null){ this.catalogToCreate={ name: this.generalForm.value.name, @@ -114,14 +128,11 @@ export class CreateCatalogComponent implements OnInit { } console.log('CATALOG TO CREATE:') console.log(this.catalogToCreate) - this.showGeneral=false; - this.showSummary=true; - this.selectStep('summary','summary-circle'); } - this.showPreview=false; } createCatalog(){ + this.setCatalogData(); this.loading=true; this.api.postCatalog(this.catalogToCreate).subscribe({ next: data => { @@ -289,4 +300,45 @@ export class CreateCatalogComponent implements OnInit { return false } } + + goToStep(index: number) { + // Solo validar en modo creación + if (index > this.currentStep) { + // Validar el paso actual + const currentStepValid = this.validateCurrentStep(); + if (!currentStepValid) { + return; // No permitir avanzar si el paso actual no es válido + } + } + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + + if(this.currentStep==1){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + case 1: // Product Specification + return true; + default: + return true; + } + } + + canNavigate(index: number) { + return (this.generalForm?.valid && (index <= this.currentStep)) || (this.generalForm?.valid && (index <= this.highestStep)); + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } } diff --git a/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.html b/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.html index fa2b7615..25825dc3 100644 --- a/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.html @@ -26,36 +26,29 @@
-

{{ 'UPDATE_CATALOG._update' | translate }}

-
-
-
- - -
- -
+

{{ 'UPDATE_CATALOG._update' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+ +

{{ this.steps[currentStep] }}

+
- @if(showGeneral){ -

{{ 'UPDATE_CATALOG._general' | translate }}

+ @if (currentStep === 0) {
{{ 'UPDATE_
-
- + + + +
diff --git a/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.ts b/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.ts index e85f50bf..e955317e 100644 --- a/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-catalogs/update-catalog/update-catalog.component.ts @@ -25,6 +25,12 @@ export class UpdateCatalogComponent implements OnInit { stepsElements:string[]=['general-info','summary']; stepsCircles:string[]=['general-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -112,6 +118,14 @@ export class UpdateCatalogComponent implements OnInit { } showFinish(){ + this.setCatalogData(); + this.showGeneral=false; + this.showSummary=true; + this.selectStep('summary','summary-circle'); + this.showPreview=false; + } + + setCatalogData(){ if(this.generalForm.value.name!=null){ this.catalogToUpdate={ description: this.generalForm.value.description != null ? this.generalForm.value.description : '', @@ -120,16 +134,11 @@ export class UpdateCatalogComponent implements OnInit { if(this.cat.name != this.generalForm.value.name){ this.catalogToUpdate.name=this.generalForm.value.name; } - console.log('CATALOG TO UPDATE:') - console.log(this.catalogToUpdate) - this.showGeneral=false; - this.showSummary=true; - this.selectStep('summary','summary-circle'); } - this.showPreview=false; } createCatalog(){ + this.showFinish(); this.loading=true; this.api.updateCatalog(this.catalogToUpdate,this.cat.id).subscribe({ next: data => { @@ -297,5 +306,38 @@ export class UpdateCatalogComponent implements OnInit { return false } } + + goToStep(index: number) { + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + + if(this.currentStep==1){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + case 1: // Product Specification + return true; + default: + return true; + } + } + + canNavigate(index: number) { + return this.generalForm?.valid + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } } diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html index e97e1c51..119fe6c6 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.html @@ -27,116 +27,27 @@
-

{{ 'CREATE_PROD_SPEC._new' | translate }}

-
-
-
- - - @if(BUNDLE_ENABLED){ -
- - } -
- -
- -
- -
- -
- -
- -
- - -
+

{{ 'CREATE_PROD_SPEC._new' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'CREATE_PROD_SPEC._general' | translate }}

+ @if (currentStep === 0) {
@@ -163,28 +74,16 @@

{{ 'CREATE_ - @if(BUNDLE_ENABLED){ -
- -
- }@else{ -
- -
- } + } - @if(showBundle){ -

{{ 'CREATE_PROD_SPEC._bundle' | translate }}

+ @if (currentStep === 1 && BUNDLE_ENABLED) {
} } -
-
- + -->
} - @if(showChars){ -

{{ 'CREATE_PROD_SPEC._chars' | translate }}

+ @if ((currentStep === 2 && !BUNDLE_ENABLED) || (currentStep === 3 && BUNDLE_ENABLED)) { @if (prodChars.length === 0){
} -
-
-

{{ 'CREATE_PROD_SPEC._add_prod_img' | translate }}

+
@if(showImgPreview){
@@ -1118,17 +1012,16 @@

{{ 'CREATE_PROD_SPEC._add_att

} -
-
+ +
+ + + + @if ((currentStep === 7 && !BUNDLE_ENABLED) || (currentStep === 8 && BUNDLE_ENABLED)) { + + } +
diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts index efef7bac..a29636a8 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/create-product-spec/create-product-spec.component.ts @@ -66,6 +66,9 @@ export class CreateProductSpecComponent implements OnInit { stepsElements:string[]=['general-info','bundle','compliance','chars','resource','service','attach','relationships','summary']; stepsCircles:string[]=['general-circle','bundle-circle','compliance-circle','chars-circle','resource-circle','service-circle','attach-circle','relationships-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps:any[] = []; showPreview:boolean=false; showEmoji:boolean=false; @@ -217,6 +220,31 @@ export class CreateProductSpecComponent implements OnInit { public files: NgxFileDropEntry[] = []; ngOnInit() { + if(this.BUNDLE_ENABLED){ + this.steps = [ + 'General Info', + 'Bundle', + 'Compliance profile', + 'Characteristics', + 'Resource specifications', + 'Service specifications', + 'Attachments', + 'Relationships', + 'Summary' + ] + } else { + this.steps = [ + 'General Info', + 'Compliance profile', + 'Characteristics', + 'Resource specifications', + 'Service specifications', + 'Attachments', + 'Relationships', + 'Summary' + ] + } + console.log(this.steps) this.initPartyInfo(); } @@ -525,7 +553,7 @@ export class CreateProductSpecComponent implements OnInit { } }); } - if(this.showAttach){ + if((this.currentStep === 5 && !this.BUNDLE_ENABLED) || (this.currentStep === 6 && this.BUNDLE_ENABLED)){ console.log(file) this.attachmentService.uploadFile(fileBody).subscribe({ next: data => { @@ -1387,4 +1415,83 @@ export class CreateProductSpecComponent implements OnInit { } } + goToStep(index: number) { + // Solo validar en modo creación + if (index > this.currentStep) { + // Validar el paso actual + const currentStepValid = this.validateCurrentStep(); + if (!currentStepValid) { + return; // No permitir avanzar si el paso actual no es válido + } + } + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //Resource + if((this.currentStep==4 && this.BUNDLE_ENABLED) || (this.currentStep==3 && !this.BUNDLE_ENABLED)){ + this.getResSpecs(false); + } + //Service + if((this.currentStep==5 && this.BUNDLE_ENABLED) || (this.currentStep==4 && !this.BUNDLE_ENABLED)){ + this.getServSpecs(false); + } + //Attachment + if((this.currentStep==6 && this.BUNDLE_ENABLED) || (this.currentStep==5 && !this.BUNDLE_ENABLED)){ + setTimeout(() => { + initFlowbite(); + }, 100); + } + //rels + if((this.currentStep==7 && this.BUNDLE_ENABLED) || (this.currentStep==6 && !this.BUNDLE_ENABLED)){ + this.getProdSpecsRel(false); + } + //finish + if((this.currentStep==8 && this.BUNDLE_ENABLED) || (this.currentStep==7 && !this.BUNDLE_ENABLED)){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + isStepDisabled(): boolean { + switch (this.currentStep) { + case 0: // General Info + return !this.generalForm?.valid || false; + case 1: + if(this.BUNDLE_ENABLED){ + return this.prodSpecsBundle.length<2 && this.bundleChecked + } else { + return this.checkValidISOS() + } + case 2: + if(this.BUNDLE_ENABLED){ + return this.checkValidISOS() + } else { + return false + } + default: + return false; + } + } + + canNavigate(index: number) { + return (this.generalForm?.valid && (index <= this.currentStep)) || (this.generalForm?.valid && (index <= this.highestStep)); + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } + } \ No newline at end of file diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.html index 1719eb19..254e1cfc 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.html @@ -27,115 +27,27 @@
-

{{ 'UPDATE_PROD_SPEC._update_prod' | translate }}

-
-
-
- - - @if(BUNDLE_ENABLED){ -
- - } -
- -
- -
- -
- -
- -
- -
- -
+

{{ 'UPDATE_PROD_SPEC._update_prod' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'UPDATE_PROD_SPEC._general' | translate }}

+ @if (currentStep === 0) {
@@ -238,28 +150,16 @@

{{ 'UPDATE_ - @if(BUNDLE_ENABLED){ -
- -
- }@else{ -
- -
- } + } - @if(showBundle){ -

{{ 'UPDATE_PROD_SPEC._bundle' | translate }}

+ @if (currentStep === 1 && BUNDLE_ENABLED) {
} } -
-
- + -->
} - @if(showChars){ -

{{ 'UPDATE_PROD_SPEC._chars' | translate }}

+ @if ((currentStep === 2 && !BUNDLE_ENABLED) || (currentStep === 3 && BUNDLE_ENABLED)) { @if (prodChars.length === 0){
} -
-
} -
-
+ +
+ + + + +
diff --git a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts index a4d3e922..c6a91443 100644 --- a/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-product-spec/update-product-spec/update-product-spec.component.ts @@ -60,6 +60,9 @@ export class UpdateProductSpecComponent implements OnInit { stepsElements:string[]=['general-info','bundle','compliance','chars','resource','service','attach','relationships','summary']; stepsCircles:string[]=['general-circle','bundle-circle','compliance-circle','chars-circle','resource-circle','service-circle','attach-circle','relationships-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps:any[] = []; showPreview:boolean=false; showEmoji:boolean=false; @@ -215,6 +218,30 @@ export class UpdateProductSpecComponent implements OnInit { public files: NgxFileDropEntry[] = []; ngOnInit() { + if(this.BUNDLE_ENABLED){ + this.steps = [ + 'General Info', + 'Bundle', + 'Compliance profile', + 'Characteristics', + 'Resource specifications', + 'Service specifications', + 'Attachments', + 'Relationships', + 'Summary' + ] + } else { + this.steps = [ + 'General Info', + 'Compliance profile', + 'Characteristics', + 'Resource specifications', + 'Service specifications', + 'Attachments', + 'Relationships', + 'Summary' + ] + } this.initPartyInfo(); console.log(this.prod) this.populateProductInfo(); @@ -729,7 +756,7 @@ export class UpdateProductSpecComponent implements OnInit { } }); } - if(this.showAttach){ + if((this.currentStep === 5 && !this.BUNDLE_ENABLED) || (this.currentStep === 6 && this.BUNDLE_ENABLED)){ console.log(file) this.attachmentService.uploadFile(fileBody).subscribe({ next: data => { @@ -1424,6 +1451,23 @@ export class UpdateProductSpecComponent implements OnInit { } showFinish() { + this.setProductData(); + this.selectStep('summary','summary-circle'); + this.showBundle=false; + this.showGeneral=false; + this.showCompliance=false; + this.showChars=false; + this.showResource=false; + this.showService=false; + this.showAttach=false; + this.showRelationships=false; + this.showSummary=true; + this.showPreview=false; + this.refreshChars(); + initFlowbite(); + } + + setProductData(){ for(let i=0; i< this.prodChars.length; i++){ const index = this.finishChars.findIndex(item => item.name === this.prodChars[i].name); if (index == -1) { @@ -1483,19 +1527,6 @@ export class UpdateProductSpecComponent implements OnInit { serviceSpecification: this.selectedServiceSpecs } } - this.selectStep('summary','summary-circle'); - this.showBundle=false; - this.showGeneral=false; - this.showCompliance=false; - this.showChars=false; - this.showResource=false; - this.showService=false; - this.showAttach=false; - this.showRelationships=false; - this.showSummary=true; - this.showPreview=false; - this.refreshChars(); - initFlowbite(); } isProdValid(){ @@ -1515,6 +1546,7 @@ export class UpdateProductSpecComponent implements OnInit { } updateProduct(){ + this.setProductData(); this.loading=true; this.prodSpecService.updateProdSpec(this.productSpecToUpdate, this.prod.id).subscribe({ next: data => { @@ -1539,6 +1571,27 @@ export class UpdateProductSpecComponent implements OnInit { }); } + isStepDisabled(): boolean { + switch (this.currentStep) { + case 0: // General Info + return !this.generalForm?.valid || false; + case 1: + if(this.BUNDLE_ENABLED){ + return this.prodSpecsBundle.length<2 && this.bundleChecked + } else { + return this.checkValidISOS() + } + case 2: + if(this.BUNDLE_ENABLED){ + return this.checkValidISOS() + } else { + return false + } + default: + return false; + } + } + //Markdown actions: addBold() { const currentText = this.generalForm.value.description; @@ -1620,4 +1673,54 @@ export class UpdateProductSpecComponent implements OnInit { } } + goToStep(index: number) { + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //Resource + if((this.currentStep==4 && this.BUNDLE_ENABLED) || (this.currentStep==3 && !this.BUNDLE_ENABLED)){ + this.getResSpecs(false); + } + //Service + if((this.currentStep==5 && this.BUNDLE_ENABLED) || (this.currentStep==4 && !this.BUNDLE_ENABLED)){ + this.getServSpecs(false); + } + //Attachment + if((this.currentStep==6 && this.BUNDLE_ENABLED) || (this.currentStep==5 && !this.BUNDLE_ENABLED)){ + setTimeout(() => { + initFlowbite(); + }, 100); + } + //rels + if((this.currentStep==7 && this.BUNDLE_ENABLED) || (this.currentStep==6 && !this.BUNDLE_ENABLED)){ + this.getProdSpecsRel(false); + } + //finish + if((this.currentStep==8 && this.BUNDLE_ENABLED) || (this.currentStep==7 && !this.BUNDLE_ENABLED)){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + canNavigate(index: number) { + return this.generalForm?.valid + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } + } diff --git a/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.html index 1d784b92..e0829101 100644 --- a/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.html @@ -26,47 +26,27 @@
-

{{ 'CREATE_RES_SPEC._new' | translate }}

-
-
-
- - -
- -
- -
+

{{ 'CREATE_RES_SPEC._new' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'CREATE_RES_SPEC._general' | translate }}

+ @if (currentStep === 0) {
{{ 'CREATE_
-
- + + + @if (currentStep === 2) { + + } +
diff --git a/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.ts index 1ac7c88c..b97f1e9c 100644 --- a/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-resource-spec/create-resource-spec/create-resource-spec.component.ts @@ -27,6 +27,13 @@ export class CreateResourceSpecComponent implements OnInit { stepsElements:string[]=['general-info','chars','summary']; stepsCircles:string[]=['general-circle','chars-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Characteristics', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -470,4 +477,44 @@ export class CreateResourceSpecComponent implements OnInit { return false } } + + goToStep(index: number) { + // Solo validar en modo creación + if (index > this.currentStep) { + // Validar el paso actual + const currentStepValid = this.validateCurrentStep(); + if (!currentStepValid) { + return; // No permitir avanzar si el paso actual no es válido + } + } + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //finish + if(this.currentStep==2){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + canNavigate(index: number) { + return (this.generalForm?.valid && (index <= this.currentStep)) || (this.generalForm?.valid && (index <= this.highestStep)); + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } } diff --git a/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.html index 4b46f733..bc0fbc8a 100644 --- a/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.html @@ -26,47 +26,27 @@
-

{{ 'UPDATE_RES_SPEC._update_res' | translate }}

-
-
-
- - -
- -
- -
+

{{ 'UPDATE_RES_SPEC._update_res' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'UPDATE_RES_SPEC._general' | translate }}

+ @if (currentStep === 0) {
{{ 'UPDATE_
-
- + + + +
diff --git a/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.ts index 2156a2a8..a1bb2b75 100644 --- a/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-resource-spec/update-resource-spec/update-resource-spec.component.ts @@ -29,6 +29,13 @@ export class UpdateResourceSpecComponent implements OnInit { stepsElements:string[]=['general-info','chars','summary']; stepsCircles:string[]=['general-circle','chars-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Characteristics', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -271,6 +278,16 @@ export class UpdateResourceSpecComponent implements OnInit { } showFinish(){ + this.setResourceData(); + this.showChars=false; + this.showGeneral=false; + this.showSummary=true; + this.selectStep('summary','summary-circle'); + this.refreshChars(); + this.showPreview=false; + } + + setResourceData(){ if(this.generalForm.value.name!=null){ this.resourceToUpdate={ name: this.generalForm.value.name, @@ -278,16 +295,11 @@ export class UpdateResourceSpecComponent implements OnInit { lifecycleStatus: this.resStatus, resourceSpecCharacteristic: this.prodChars } - this.showChars=false; - this.showGeneral=false; - this.showSummary=true; - this.selectStep('summary','summary-circle'); - this.refreshChars(); } - this.showPreview=false; } updateResource(){ + this.setResourceData(); this.loading=true; this.resSpecService.updateResSpec(this.resourceToUpdate,this.res.id).subscribe({ next: data => { @@ -470,4 +482,41 @@ export class UpdateResourceSpecComponent implements OnInit { } } + goToStep(index: number) { + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //chars + if(this.currentStep==1){ + setTimeout(() => { + initFlowbite(); + }, 100); + } + //finish + if(this.currentStep==2){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + canNavigate(index: number) { + return this.generalForm?.valid + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } + } diff --git a/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.html index 7b59cef0..61e8d815 100644 --- a/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.html @@ -26,47 +26,27 @@
-

{{ 'CREATE_SERV_SPEC._new' | translate }}

-
-
-
- - -
- -
- -
+

{{ 'CREATE_SERV_SPEC._new' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'CREATE_SERV_SPEC._general' | translate }}

+ @if (currentStep === 0) {
{{ 'CREATE_
-
- + + + @if (currentStep === 2) { + + } +
diff --git a/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.ts index cbcd405d..931eccf1 100644 --- a/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-service-spec/create-service-spec/create-service-spec.component.ts @@ -27,6 +27,13 @@ export class CreateServiceSpecComponent implements OnInit { stepsElements:string[]=['general-info','chars','summary']; stepsCircles:string[]=['general-circle','chars-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Characteristics', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -462,4 +469,44 @@ export class CreateServiceSpecComponent implements OnInit { } } + goToStep(index: number) { + // Solo validar en modo creación + if (index > this.currentStep) { + // Validar el paso actual + const currentStepValid = this.validateCurrentStep(); + if (!currentStepValid) { + return; // No permitir avanzar si el paso actual no es válido + } + } + + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //finish + if(this.currentStep==2){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + canNavigate(index: number) { + return (this.generalForm?.valid && (index <= this.currentStep)) || (this.generalForm?.valid && (index <= this.highestStep)); + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } + } diff --git a/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.html b/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.html index ded8bef9..d1115190 100644 --- a/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.html +++ b/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.html @@ -26,47 +26,27 @@
-

{{ 'UPDATE_SERV_SPEC._update_serv' | translate }}

-
-
-
- - -
- -
- -
+

{{ 'UPDATE_SERV_SPEC._update_serv' | translate }}

+
    + @for (step of steps; track i; let i = $index) { +
  1. + + {{ i + 1 }} + + +
  2. + } +
+
- @if(showGeneral){ -

{{ 'UPDATE_SERV_SPEC._general' | translate }}

+ @if (currentStep === 0) {
{{ 'UPDATE_
-
- + + + +
diff --git a/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.ts b/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.ts index bb0c96fc..38a6ce54 100644 --- a/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.ts +++ b/src/app/pages/seller-offerings/offerings/seller-service-spec/update-service-spec/update-service-spec.component.ts @@ -29,6 +29,13 @@ export class UpdateServiceSpecComponent implements OnInit { stepsElements:string[]=['general-info','chars','summary']; stepsCircles:string[]=['general-circle','chars-circle','summary-circle']; + currentStep = 0; + highestStep = 0; + steps = [ + 'General Info', + 'Characteristics', + 'Summary' + ]; //markdown variables: showPreview:boolean=false; @@ -267,6 +274,16 @@ export class UpdateServiceSpecComponent implements OnInit { } showFinish(){ + this.setServiceData(); + this.showChars=false; + this.showGeneral=false; + this.showSummary=true; + this.selectStep('summary','summary-circle'); + this.refreshChars(); + this.showPreview=false; + } + + setServiceData(){ if(this.generalForm.value.name!=null){ this.serviceToUpdate={ name: this.generalForm.value.name, @@ -274,16 +291,11 @@ export class UpdateServiceSpecComponent implements OnInit { lifecycleStatus: this.servStatus, specCharacteristic: this.prodChars } - this.showChars=false; - this.showGeneral=false; - this.showSummary=true; - this.selectStep('summary','summary-circle'); - this.refreshChars(); } - this.showPreview=false; } updateService(){ + this.setServiceData(); this.loading=true; this.servSpecService.updateServSpec(this.serviceToUpdate,this.serv.id).subscribe({ next: data => { @@ -466,4 +478,41 @@ export class UpdateServiceSpecComponent implements OnInit { } } + goToStep(index: number) { + this.currentStep = index; + if(this.currentStep>this.highestStep){ + this.highestStep=this.currentStep + } + this.refreshChars(); + //chars + if(this.currentStep==1){ + setTimeout(() => { + initFlowbite(); + }, 100); + } + //finish + if(this.currentStep==2){ + this.showFinish(); + } + } + + validateCurrentStep(): boolean { + switch (this.currentStep) { + case 0: // General Info + return this.generalForm?.valid || false; + default: + return true; + } + } + + canNavigate(index: number) { + return this.generalForm?.valid + } + + handleStepClick(index: number): void { + if (this.canNavigate(index)) { + this.goToStep(index); + } + } + } diff --git a/src/app/services/app-init.service.ts b/src/app/services/app-init.service.ts index 89a8b8cf..e9f9e7bd 100644 --- a/src/app/services/app-init.service.ts +++ b/src/app/services/app-init.service.ts @@ -35,7 +35,7 @@ export class AppInitService { environment.analytics = config.analytics ?? 'https://analytics.dome-marketplace-sbx.org/', environment.feedbackCampaign = config.feedbackCampaign ?? false, environment.feedbackCampaignExpiration = config.feedbackCampaign ?? moment().add(1, 'week').unix() - environment.providerThemeName = 'DOME'; + environment.providerThemeName = config.theme ?? 'default'; environment.QUOTES_ENABLED = config.quotesEnabled ?? false resolve(config); }), diff --git a/src/app/services/price-service.service.ts b/src/app/services/price-service.service.ts index 47fdfcdf..f0cdb8e2 100644 --- a/src/app/services/price-service.service.ts +++ b/src/app/services/price-service.service.ts @@ -107,7 +107,7 @@ export class PriceServiceService { if (offering?.productOfferingPrice && offering?.productOfferingPrice.length > 0) { // Check if the first POP is a custom one const pop = await this.getProductPrice(offering.productOfferingPrice[0].id); - isCustom = pop.priceType.toLowerCase() === 'custom'; + isCustom = pop.priceType?.toLowerCase() === 'custom'; } return isCustom; diff --git a/src/app/shared/cart-drawer/cart-drawer.component.ts b/src/app/shared/cart-drawer/cart-drawer.component.ts index fdf16b04..59dd3d1a 100644 --- a/src/app/shared/cart-drawer/cart-drawer.component.ts +++ b/src/app/shared/cart-drawer/cart-drawer.component.ts @@ -26,6 +26,8 @@ export class CartDrawerComponent implements OnInit{ showBackDrop:boolean=true; check_custom:boolean=false; loading:boolean=false; + errorMessage:string=''; + showError:boolean=false; constructor( private localStorage: LocalStorageService, @@ -46,42 +48,16 @@ export class CartDrawerComponent implements OnInit{ ngOnInit(): void { this.loading=true; this.showBackDrop=true; - this.cartService.getShoppingCart().then(async data => { - console.log('---CARRITO API---') - console.log(data) - this.items=data; - await this.getProviderInfo(); - this.groupItemsByOwner(); - this.loading=false; - this.cdr.detectChanges(); - console.log('------------------') - }) + this.getCart(); + this.eventMessage.messages$.subscribe(ev => { if(ev.type === 'AddedCartItem') { console.log('Elemento añadido') this.loading=true; - this.cartService.getShoppingCart().then(async data => { - console.log('---CARRITO API---') - console.log(data) - this.items=data; - await this.getProviderInfo(); - this.groupItemsByOwner(); - this.loading=false; - this.cdr.detectChanges(); - console.log('------------------') - }) + this.getCart(); } else if(ev.type === 'RemovedCartItem') { this.loading=true; - this.cartService.getShoppingCart().then(async data => { - console.log('---CARRITO API---') - console.log(data) - this.items=data; - await this.getProviderInfo(); - this.groupItemsByOwner(); - this.loading=false; - this.cdr.detectChanges(); - console.log('------------------') - }) + this.getCart(); } }) console.log('Elementos en el carrito....') @@ -92,6 +68,31 @@ export class CartDrawerComponent implements OnInit{ return Object.keys; } + getCart(){ + try { + this.cartService.getShoppingCart().then(async data => { + console.log('---CARRITO API---') + console.log(data) + this.items=data; + await this.getProviderInfo(); + this.groupItemsByOwner(); + this.loading=false; + this.cdr.detectChanges(); + console.log('------------------') + }) + } catch (error) { + this.loading=false; + this.handleError(error, 'There was an error while retrieving the cart!'); + } + } + + private handleError(error: any, defaultMessage: string) { + console.error(defaultMessage, error); + this.errorMessage = error?.error?.error ? `Error: ${error.error.error}` : defaultMessage; + this.showError = true; + setTimeout(() => (this.showError = false), 3000); + } + hasKey(obj: any, key: string): boolean { return key in obj; } @@ -119,9 +120,22 @@ export class CartDrawerComponent implements OnInit{ async getProviderInfo(){ for(let i=0; i < this.items.length; i++){ - let offer = await this.api.getProductById(this.items[i].id); - let product = await this.api.getProductSpecification(offer.productSpecification.id) - this.items[i]['relatedParty']=product.relatedParty + try { + let offer = await this.api.getProductById(this.items[i].id); + let product = await this.api.getProductSpecification(offer.productSpecification.id) + this.items[i]['relatedParty']=product.relatedParty + } catch (error) { + console.log('--- not found?') + console.log(error) + if((error as any).status==404){ + await this.cartService.removeItemShoppingCart(this.items[i].id); + console.log('deleted'); + this.eventMessage.emitRemovedCartItem(this.items[i] as cartProduct); + } + this.loading=false; + this.handleError(error, "There was an error while retrieving cart's product information!"); + } + } } @@ -129,7 +143,7 @@ export class CartDrawerComponent implements OnInit{ const groupedByOwner: any[][] = Object.values( this.items.reduce((groups: any, item: any) => { const owner = item.relatedParty - ?.find((rp: any) => rp.role === 'Owner') + ?.find((rp: any) => rp.role === 'Seller') ?.id; if (owner) {