Travel descriptor now shows delete option if there are no entries

This commit is contained in:
Carlos Jimenez Ruiz 2021-06-15 16:41:01 +02:00
parent bbac4483cd
commit 8aa3d269ea
4 changed files with 43 additions and 1 deletions

View File

@ -18,6 +18,13 @@
translate>
Clone travel and his entries
</vn-item>
<vn-item
id="delete"
ng-click="delete.show()"
ng-show="$ctrl.isBuyer && !$ctrl.entries.length"
translate>
Delete travel
</vn-item>
<a class="vn-item"
ui-sref="entry.create({travelFk: $ctrl.travel.id})"
name="addEntry"
@ -35,6 +42,14 @@
message="All it's properties will be copied">
</vn-confirm>
<!-- Delete travel popup -->
<vn-confirm
vn-id="delete"
on-accept="$ctrl.onDeleteAccept()"
question="Do you want to delete this travel?"
message="The travel will be deleted">
</vn-confirm>
<!-- Clone travel popup -->
<vn-confirm
vn-id="cloneWithEntries"

View File

@ -44,14 +44,23 @@ class Controller extends Section {
}
]
};
return this.$http.get(`Travels/${this.travelId}`, {filter})
this.$http.get(`Travels/${this.travelId}`, {filter})
.then(res => this.travel = res.data);
this.$http.get(`Travels/${this.travelId}/getEntries`)
.then(res => this.entries = res.data);
}
get isBuyer() {
return this.aclService.hasAny(['buyer']);
}
onDeleteAccept() {
this.$http.delete(`Travels/${this.travelId}`)
.then(() => this.$state.go('travel.index'))
.then(() => this.vnApp.showSuccess(this.$t('Travel deleted')));
}
onCloneAccept() {
const params = JSON.stringify({
ref: this.travel.ref,

View File

@ -40,6 +40,21 @@ describe('Travel Component vnTravelDescriptorMenu', () => {
});
});
describe('onDeleteAccept()', () => {
it('should perform a delete query', () => {
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');
controller.travelId = 1;
$httpBackend.when('GET', `Travels/${controller.travelId}`).respond(200);
$httpBackend.when('GET', `Travels/${controller.travelId}/getEntries`).respond(200);
$httpBackend.expect('DELETE', `Travels/${controller.travelId}`).respond(200);
controller.onDeleteAccept();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('travel.index');
});
});
describe('onCloneWithEntriesAccept()', () => {
it('should make an HTTP query and then call to the $state.go method with the returned id', () => {
jest.spyOn(controller.$state, 'go').mockReturnValue('ok');

View File

@ -2,3 +2,6 @@ Clone travel: Clonar envío
Add entry: Añadir entrada
Clone travel and his entries: Clonar travel y sus entradas
Do you want to clone this travel and all containing entries?: ¿Quieres clonar este travel y todas las entradas que contiene?
Delete travel: Borrar envío
The travel will be deleted: El envío será borrado
Do you want to delete this travel?: ¿Quieres borrar este envío?