Merge pull request '2965-delete_travel_from_descriptor' (#656) from 2965-delete_travel_from_descriptor into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #656
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2021-06-16 09:48:58 +00:00
commit b7342ec15d
4 changed files with 44 additions and 1 deletions

View File

@ -18,6 +18,13 @@
translate> translate>
Clone travel and his entries Clone travel and his entries
</vn-item> </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" <a class="vn-item"
ui-sref="entry.create({travelFk: $ctrl.travel.id})" ui-sref="entry.create({travelFk: $ctrl.travel.id})"
name="addEntry" name="addEntry"
@ -35,6 +42,14 @@
message="All it's properties will be copied"> message="All it's properties will be copied">
</vn-confirm> </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 --> <!-- Clone travel popup -->
<vn-confirm <vn-confirm
vn-id="cloneWithEntries" 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); .then(res => this.travel = res.data);
this.$http.get(`Travels/${this.travelId}/getEntries`)
.then(res => this.entries = res.data);
} }
get isBuyer() { get isBuyer() {
return this.aclService.hasAny(['buyer']); 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() { onCloneAccept() {
const params = JSON.stringify({ const params = JSON.stringify({
ref: this.travel.ref, 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()', () => { describe('onCloneWithEntriesAccept()', () => {
it('should make an HTTP query and then call to the $state.go method with the returned id', () => { 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'); jest.spyOn(controller.$state, 'go').mockReturnValue('ok');

View File

@ -2,3 +2,7 @@ Clone travel: Clonar envío
Add entry: Añadir entrada Add entry: Añadir entrada
Clone travel and his entries: Clonar travel y sus entradas 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? Do you want to clone this travel and all containing entries?: ¿Quieres clonar este travel y todas las entradas que contiene?
Delete travel: Eliminar envío
The travel will be deleted: El envío será eliminado
Do you want to delete this travel?: ¿Quieres eliminar este envío?
Travel deleted: Envío eliminado