CI and services features

This commit is contained in:
Matteo Gheza 2021-03-23 18:45:47 +01:00
parent d2be7a914f
commit ee6f149d5c
9 changed files with 130 additions and 3 deletions

View File

@ -0,0 +1 @@
[{"place_id":257830288,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":44882,"boundingbox":["45.2042549","46.3548531","9.8362928","10.842675"],"lat":"45.77958045","lon":"10.4258729694612","display_name":"Brescia, Lombardy, Italy","class":"boundary","type":"administrative","importance":0.7354640205264362,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":257390216,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":45144,"boundingbox":["45.4807171","45.5899752","10.1470684","10.3002186"],"lat":"45.5398022","lon":"10.2200214","display_name":"Brescia, Lombardy, Italy","class":"boundary","type":"administrative","importance":0.7271074461208031,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":54063101,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":4553822557,"boundingbox":["45.5273342","45.5373342","10.2078404","10.2178404"],"lat":"45.5323342","lon":"10.2128404","display_name":"Brescia, Piazzale Stazione, Centro Storico Sud, Zona Centro, Brescia, Lombardy, 25122, Italy","class":"railway","type":"station","importance":0.48614554653236075,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//transport_train_station2.p.20.png"},{"place_id":23143065,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":2409443276,"boundingbox":["44.4687976","44.4688976","8.6048681","8.6049681"],"lat":"44.4688476","lon":"8.6049181","display_name":"Brescia, Urbe, Savona, Liguria, 17048, Italy","class":"place","type":"isolated_dwelling","importance":0.29999999999999993},{"place_id":197395200,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"way","osm_id":474271843,"boundingbox":["20.5751086","20.5752334","-103.3814379","-103.3805205"],"lat":"20.5751086","lon":"-103.3808414","display_name":"Brescia, Tlaquepaque, San Pedro Tlaquepaque, Jalisco, 45602, Mexico","class":"highway","type":"living_street","importance":0.19999999999999998}]

View File

@ -0,0 +1 @@
[{"place_id":258244980,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":44915,"boundingbox":["45.3867381","45.5358482","9.0408867","9.2781103"],"lat":"45.4668","lon":"9.1905","display_name":"Milano, Lombardia, Italia","class":"boundary","type":"administrative","importance":0.8390652078701348,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":258789516,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":344499,"boundingbox":["41.0766967","41.1206314","-6.6489375","-6.566364"],"lat":"41.0923837","lon":"-6.5984217","display_name":"El Milano, Salamanca, Castiglia e León, Spagna","class":"boundary","type":"administrative","importance":0.6058586680411897,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":258556780,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":44881,"boundingbox":["45.1614258","45.6434829","8.7060961","9.551457"],"lat":"45.454211900000004","lon":"9.111350961779705","display_name":"Milano, Lombardia, Italia","class":"boundary","type":"administrative","importance":0.6027406455537151,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":259530334,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":6605766,"boundingbox":["30.696897","30.718944","-96.881245","-96.841162"],"lat":"30.7106407","lon":"-96.864745","display_name":"Milano, Milam County, Texas, 76556, Stati Uniti d'America","class":"boundary","type":"administrative","importance":0.5332195319778348,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"},{"place_id":5770611,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"node","osm_id":650721553,"boundingbox":["42.7623859","42.8023859","12.5780599","12.6180599"],"lat":"42.7823859","lon":"12.5980599","display_name":"Milano, Spoleto, Perugia, Umbria, 06049, Italia","class":"place","type":"hamlet","importance":0.5316717311890431,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_place_village.p.20.png"}]

View File

@ -0,0 +1,115 @@
describe("Service management", () => {
beforeEach(() => {
cy.login();
cy.intercept('https://nominatim.openstreetmap.org/search?format=json&limit=5&q=brescia', { fixture: 'nominatim_brescia.json' });
cy.intercept('https://nominatim.openstreetmap.org/search?format=json&limit=5&q=milano', { fixture: 'nominatim_milano.json' });
})
it('Add Service with new type', function () {
cy.get('tr:has(> td:has(> a[id="username-11"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-4"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-9"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-7"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-2"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-6"])) > :nth-child(6)').should('contain', '0');
cy.visit("/edit_service.php?add", {
onBeforeLoad(win) {
cy.stub(win, 'prompt').returns('test')
}
});
cy.get('.form-control').clear();
cy.get('.form-control').type('07/12/2020');
cy.window().then(win => win.$('.datepicker').remove());
cy.get('#progressivo').clear();
cy.get('#progressivo').type('1234/5');
cy.get('#timePicker1').clear();
cy.get('#timePicker1').type('10:10');
cy.get('#timePicker2').clear();
cy.get('#timePicker2').type('23:59');
cy.get('.chief-11').check();
cy.get('.drivers-7').check();
cy.get('.drivers-6').check();
cy.get('.crew-2').check();
cy.get('.crew-4').check();
cy.get('.crew-9').check();
cy.get('#addr').clear();
cy.get('#addr').type('brescia');
cy.get('.btn').click();
cy.get('#search').click();
cy.get('.results-list > :nth-child(1) > a').click();
cy.get('#notes').click();
cy.stub(window, 'prompt').returns('test')
cy.get('.types').select('add_new');
cy.wait('@ajax_add_type');
cy.get('[type="submit"]').click();
cy.wait('@ajax_services');
cy.contains("2020-07-12");
cy.contains("1234/5");
cy.visit("/log.php");
cy.wait('@ajax_log');
cy.contains("Aggiunto intervento");
cy.visit("/list.php");
cy.wait('@ajax_list');
cy.get('tr:has(> td:has(> a[id="username-11"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-4"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-9"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-7"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-2"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-6"])) > :nth-child(6)').should('contain', '1');
});
it('Edit service', function() {
cy.visit("/services.php");
cy.wait('@ajax_services');
cy.get('#row-0 > .dtr-control').click();
cy.get('.dtr-details a[data-action="edit"]').click();
cy.get('#progressivo').clear();
cy.get('#progressivo').type('4321/5');
cy.get('.chief-11').uncheck();
cy.get('.chief-8').check();
cy.get('.crew-4').uncheck();
cy.get('.crew-9').uncheck();
cy.get('.crew-3').check();
cy.get('.crew-5').check();
cy.get('#addr').clear();
cy.get('#addr').type('milano');
cy.get('.btn').click();
cy.get('.results-list > :nth-child(1) > a').click();
cy.get('[type="submit"]').click();
cy.wait('@ajax_services');
cy.contains("2020-07-12");
cy.contains("4321/5");
cy.visit("/log.php");
cy.wait('@ajax_log');
cy.contains("Modificato intervento");
cy.visit("/list.php");
cy.wait('@ajax_list');
cy.get('tr:has(> td:has(> a[id="username-11"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-8"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-4"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-9"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-3"])) > :nth-child(6)').should('contain', '1');
cy.get('tr:has(> td:has(> a[id="username-5"])) > :nth-child(6)').should('contain', '1');
});
it('Delete Service', function() {
cy.visit("/services.php");
cy.wait('@ajax_services');
cy.get('#row-0 > .dtr-control').click();
cy.get('.dtr-details a[data-action="delete"]').click();
cy.get('#remove').click();
cy.wait('@ajax_services');
cy.visit("/log.php");
cy.wait('@ajax_log');
cy.contains("Rimosso intervento");
cy.visit("/list.php");
cy.wait('@ajax_list');
cy.get('tr:has(> td:has(> a[id="username-8"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-3"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-5"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-7"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-2"])) > :nth-child(6)').should('contain', '0');
cy.get('tr:has(> td:has(> a[id="username-6"])) > :nth-child(6)').should('contain', '0');
});
})

View File

@ -8,6 +8,7 @@ Cypress.Commands.add("login", (username="admin", password="correcthorsebatteryst
cy.setCookie("forceLanguage", "en");
cy.setCookie('disableServiceWorkerInstallation', '1');
cy.intercept(Cypress.config('baseUrl')+'resources/ajax/ajax_add_type.php').as('ajax_add_type');
cy.intercept(Cypress.config('baseUrl')+'resources/ajax/ajax_change_availability.php').as('ajax_change_availability');
cy.intercept(Cypress.config('baseUrl')+'resources/ajax/ajax_list.php').as('ajax_list');
cy.intercept(Cypress.config('baseUrl')+'resources/ajax/ajax_log.php').as('ajax_log');

View File

@ -8,6 +8,7 @@ if($tools->validate_form("mod", "add")) {
if($_POST["token"] == $_SESSION['token']) {
bdump("adding service");
$database->add_service($_POST["date"], $_POST["code"], $_POST["beginning"], $_POST["end"], $_POST["chief"][0], $tools->extract_unique($_POST["drivers"]), $tools->extract_unique($_POST["crew"]), $_POST["place"], $_POST["notes"], $_POST["type"], $tools->extract_unique([$_POST["chief"],$_POST["drivers"],$_POST["crew"]]), $user->name());
$user->log("Aggiunto intervento", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("services.php");
} else {
debug(); //TODO: remove debug info
@ -21,6 +22,7 @@ if($tools->validate_form("mod", "add")) {
bdump($_POST);
bdump("editing service");
$database->change_service($_POST["id"], $_POST["date"], $_POST["code"], $_POST["beginning"], $_POST["end"], $_POST["chief"][0], $tools->extract_unique($_POST["drivers"]), $tools->extract_unique($_POST["crew"]), $_POST["place"], $_POST["notes"], $_POST["type"], $tools->extract_unique([$_POST["chief"],$_POST["drivers"],$_POST["crew"]]), $user->name());
$user->log("Modificato intervento", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("services.php");
} else {
debug();
@ -34,6 +36,7 @@ if($tools->validate_form("mod", "add")) {
if($_POST["token"] == $_SESSION['token']) {
bdump("removing service");
$database->remove_service($_POST["id"], $_POST["increment"]);
$user->log("Rimosso intervento", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("services.php");
} else {
echo("1");

View File

@ -8,6 +8,7 @@ if($tools->validate_form("mod", "add")) {
if($_POST["token"] == $_SESSION['token']) {
bdump("adding training");
$database->add_training($_POST["date"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["chief"][0], $tools->extract_unique($_POST["crew"]), $_POST["place"], $_POST["notes"], $tools->extract_unique([$_POST["chief"],$_POST["crew"]]), $user->name());
$user->log("Aggiunta esercitazione", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("trainings.php");
} else {
debug(); //TODO: remove debug info
@ -21,6 +22,7 @@ if($tools->validate_form("mod", "add")) {
bdump($_POST);
bdump("editing training");
$database->change_training($_POST["id"], $_POST["date"], $_POST["name"], $_POST["start_time"], $_POST["end_time"], $_POST["chief"][0], $tools->extract_unique($_POST["crew"]), $_POST["place"], $_POST["notes"], $tools->extract_unique([$_POST["chief"],$_POST["crew"]]), $user->name());
$user->log("Modificata esercitazione", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("trainings.php");
} else {
debug();
@ -34,6 +36,7 @@ if($tools->validate_form("mod", "add")) {
if($_POST["token"] == $_SESSION['token']) {
bdump("removing training");
$database->remove_training($_POST["id"], $_POST["increment"]);
$user->log("Rimossa esercitazione", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("trainings.php");
} else {
debug();

View File

@ -28,6 +28,8 @@ if($tools->validate_form("mod", "add")) {
exit();
}
$user->add_user($_POST["mail"], $_POST["name"], $_POST["username"], $_POST["password"], $phone_number, $_POST["birthday"], $chief, $driver, $hidden, $disabled, $user->name());
//TODO: move and translate logs
//$user->log("Aggiunto utente", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("list.php");
} else {
debug();
@ -53,6 +55,7 @@ if($tools->validate_form("mod", "add")) {
if($_POST["token"] == $_SESSION['token']) {
bdump("removing user");
$user->remove_user($_POST["id"]);
$user->log("Rimosso utente", $user->auth->getUserId(), $user->auth->getUserId(), date("d/m/Y"), date("H:i.s"));
$tools->redirect("list.php");
} else {
debug();

View File

@ -32,8 +32,8 @@ foreach($risultato as $row){
s($row['place'],false,true),
s($row['notes'],false,true),
s($row['type'],false,true),
$database->getOption("service_edit") ? "<a class='pjax_disable' href='edit_service.php?edit&id={$row['id']}'><i style='font-size: 40px' class='fa fa-edit'></i></a>" : null,
$database->getOption("service_remove") ? "<a class='pjax_disable' href='edit_service.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a>" : null
$database->getOption("service_edit") ? "<a class='pjax_disable' data-action='edit' href='edit_service.php?edit&id={$row['id']}'><i style='font-size: 40px' class='fa fa-edit'></i></a>" : null,
$database->getOption("service_remove") ? "<a class='pjax_disable' data-action='delete' href='edit_service.php?delete&id={$row['id']}&increment={$row['increment']}'><i style='font-size: 40px' class='fa fa-trash'></i></a>" : null
];
}
$tools->ajax_page_response($response);

View File

@ -182,7 +182,7 @@
<input id="token" type="hidden" value="{{ service.token }}" name="token"></input>
<input id="id" type="hidden" value="{{ service.id }}" name="id"></input>
<input id="increment" type="hidden" value="{{ increment }}" name="increment"></input>
<button id="add" type="submit">{{ 'Submit'|t }}</button>
<button id="remove" type="submit">{{ 'Submit'|t }}</button>
</form>
<script>
$('form').submit(function () {