Browse Source

Merge pull request 'staging' (#21) from staging into master

Reviewed-on: ordo/adw-gantt#21
pull/1/head
ibnu 1 year ago
parent
commit
0adcb59b52
  1. 132
      edit-mode/function/activityLocation.js
  2. 45
      edit-mode/function/ganttConfig.js

132
edit-mode/function/activityLocation.js

@ -6,10 +6,10 @@ let zoom = 10;
let currentIdAct = 0; let currentIdAct = 0;
let map = L.map('map_activity').setView([lat, long], zoom); let map = L.map('map_activity').setView([lat, long], zoom);
let drawnItems = new L.FeatureGroup().addTo(map); let drawnItems = new L.FeatureGroup().addTo(map);
let inter = 5; let inter = 5;
let circLat = "", let circLat = "",
circLong = ""; circLong = "";
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
@ -18,16 +18,16 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
var drawControl = new L.Control.Draw({ var drawControl = new L.Control.Draw({
draw: { draw: {
circlemarker: false, circlemarker: false,
circle:false, circle: false,
polyline: false polyline: false
}, },
}); });
var drawnControlEdit = new L.Control.Draw({ var drawnControlEdit = new L.Control.Draw({
draw: false, draw: false,
edit:{ edit: {
featureGroup:drawnItems, featureGroup: drawnItems,
delete:true delete: true
} }
}); });
@ -43,6 +43,9 @@ function updateCurrentGeoJson() {
let shapes = []; let shapes = [];
drawnItems.eachLayer(function (layer) { drawnItems.eachLayer(function (layer) {
let geojson = layer.toGeoJSON(); let geojson = layer.toGeoJSON();
if (layer instanceof L.Circle) {
geojson.properties.radius = layer.getRadius();
}
shapes.push(geojson); shapes.push(geojson);
}); });
currentGeoJson = { currentGeoJson = {
@ -50,18 +53,17 @@ function updateCurrentGeoJson() {
features: shapes features: shapes
}; };
} }
function openActivityMap(id) function openActivityMap(id) {
{
currentIdAct = id; currentIdAct = id;
map.invalidateSize(); map.invalidateSize();
$.ajax({ $.ajax({
url: `${base_url}task/edit/${id}`, url: `${base_url}task/edit/${id}`,
type:"get", type: "get",
success: function (data) { success: function (data) {
let dataRes = data.data let dataRes = data.data
// console.log("cek data", data); // console.log("cek data", data);
drawnItems.clearLayers(); drawnItems.clearLayers();
if(dataRes.geom){ if (dataRes.geom) {
let datageojson = JSON.parse(dataRes.geom); let datageojson = JSON.parse(dataRes.geom);
currentGeoJson = datageojson currentGeoJson = datageojson
// console.log("cek data geojson", datageojson); // console.log("cek data geojson", datageojson);
@ -70,27 +72,35 @@ function openActivityMap(id)
let lGeoJson = L.geoJSON(feature); let lGeoJson = L.geoJSON(feature);
let layers = lGeoJson.getLayers(); let layers = lGeoJson.getLayers();
layers.forEach(layer => { layers.forEach(layer => {
addDrawnLayer(layer) let radius = layer.feature.properties.radius;
if (radius) {
let latlon = layer.getLatLng();
let circle = L.circle([latlon.lat, latlon.lng], { radius: radius });
addDrawnLayer(circle);
}
else {
addDrawnLayer(layer)
}
}); });
}); });
} else { } else {
if(datageojson.properties.radius){ if (datageojson.properties.radius) {
let radius = datageojson.properties.radius let radius = datageojson.properties.radius
let lGeoJson = L.geoJson(datageojson); let lGeoJson = L.geoJson(datageojson);
let layers = lGeoJson.getLayers(); let layers = lGeoJson.getLayers();
let latlon = layers[0].getLatLng(); let latlon = layers[0].getLatLng();
let newCircle = L.circle([latlon.lat,latlon.lng], {radius: radius}); let newCircle = L.circle([latlon.lat, latlon.lng], { radius: radius });
addDrawnLayer(newCircle) addDrawnLayer(newCircle)
// console.log("cek layers", layers[0]); // console.log("cek layers", layers[0]);
}else{ } else {
let lGeoJson = L.geoJson(datageojson); let lGeoJson = L.geoJson(datageojson);
let layers = lGeoJson.getLayers(); let layers = lGeoJson.getLayers();
addDrawnLayer(layers[0]) addDrawnLayer(layers[0])
} }
} }
actionLocationAc = "edit"; actionLocationAc = "edit";
map.addControl(drawnControlEdit); map.addControl(drawnControlEdit);
}else{ } else {
currentGeoJson = ""; currentGeoJson = "";
actionLocationAc = "add"; actionLocationAc = "add";
drawnControlEdit.remove(); drawnControlEdit.remove();
@ -105,7 +115,7 @@ function openActivityMap(id)
} }
$('#modal_activity_location').on('hide.bs.modal', function (event) { $('#modal_activity_location').on('hide.bs.modal', function (event) {
currentGeoJson ="" currentGeoJson = ""
currentIdAct = 0; currentIdAct = 0;
actionLocationAc = "add"; actionLocationAc = "add";
drawnControlEdit.remove(); drawnControlEdit.remove();
@ -116,7 +126,7 @@ $('#modal_activity_location').on('hide.bs.modal', function (event) {
// map initialization // map initialization
$(document).ready(function () { $(document).ready(function () {
let intervalMap = setInterval(function () { let intervalMap = setInterval(function () {
if(inter=0){ if (inter = 0) {
clearInterval(intervalMap) clearInterval(intervalMap)
} }
map.invalidateSize(); map.invalidateSize();
@ -129,7 +139,7 @@ $(document).ready(function () {
if (type === 'marker') { if (type === 'marker') {
let latlong = layer.getLatLng(); let latlong = layer.getLatLng();
// console.log("cek latlong", latlong); // console.log("cek latlong", latlong);
circLat = latlong.lat circLat = latlong.lat
circLong = latlong.lng circLong = latlong.lng
$("#modal_radius").modal("show"); $("#modal_radius").modal("show");
// Do marker specific actions // Do marker specific actions
@ -167,11 +177,11 @@ $(document).ready(function () {
// layer = e.layer; // layer = e.layer;
let layers = e.layers.getLayers(); let layers = e.layers.getLayers();
layers.forEach(layer => { layers.forEach(layer => {
let geoJson = layer.toGeoJSON(); let geoJson = layer.toGeoJSON();
if(layer instanceof L.Circle){ if (layer instanceof L.Circle) {
geoJson.properties.radius = layer.getRadius(); geoJson.properties.radius = layer.getRadius();
} }
updateCurrentGeoJson(); updateCurrentGeoJson();
}); });
// console.log("cek layer", layers[0].toGeoJSON()); // console.log("cek layer", layers[0].toGeoJSON());
// console.log("cek layer", layer.toGeoJSON()); // console.log("cek layer", layer.toGeoJSON());
@ -181,21 +191,21 @@ $(document).ready(function () {
// map.addLayer(layer); // map.addLayer(layer);
}); });
$("#modal_activity_location").on("click", "#btn_save_location", function() { $("#modal_activity_location").on("click", "#btn_save_location", function () {
if(currentGeoJson==""){ if (currentGeoJson == "") {
gantt.confirm({ gantt.confirm({
text: "Lokasi belum ditentukan!, lanjutkan?", text: "Lokasi belum ditentukan!, lanjutkan?",
ok:"Submit", ok: "Submit",
cancel:"Cancel", cancel: "Cancel",
callback: function(result){ callback: function (result) {
if(!result){ if (!result) {
return false return false
}else{ } else {
submitShapes(); submitShapes();
} }
} }
}); });
}else{ } else {
submitShapes(); submitShapes();
} }
}); });
@ -203,97 +213,95 @@ $(document).ready(function () {
function submitShapes() { function submitShapes() {
let payload let payload
if(currentGeoJson && currentGeoJson!=""){ if (currentGeoJson && currentGeoJson != "") {
payload = { payload = {
geom: JSON.stringify(currentGeoJson), geom: JSON.stringify(currentGeoJson),
} }
}else{ } else {
payload = { payload = {
geom: null, geom: null,
} }
} }
$.ajax({ $.ajax({
data: JSON.stringify(payload), data: JSON.stringify(payload),
url: `${base_url}task/update-regular/${currentIdAct}`, url: `${base_url}task/update-regular/${currentIdAct}`,
type: "PUT", type: "PUT",
processData: false, processData: false,
contentType: false, contentType: false,
success: function (data) { success: function (data) {
$("#modal_activity_location").modal("hide"); $("#modal_activity_location").modal("hide");
currentGeoJson ="" currentGeoJson = ""
currentIdAct = 0; currentIdAct = 0;
gantt.alert("Activity Location successfully updated!"); gantt.alert("Activity Location successfully updated!");
}, },
error: function (data) { error: function (data) {
$("#modal_activity_location").modal("hide"); $("#modal_activity_location").modal("hide");
currentGeoJson ="" currentGeoJson = ""
currentIdAct = 0; currentIdAct = 0;
gantt.alert("Activity Location failed updated!, try again later!"); gantt.alert("Activity Location failed updated!, try again later!");
} }
}); });
} }
function submitLocation() function submitLocation() {
{
let payload let payload
if(currentGeoJson && currentGeoJson!=""){ if (currentGeoJson && currentGeoJson != "") {
payload = { payload = {
geom: JSON.stringify(currentGeoJson), geom: JSON.stringify(currentGeoJson),
} }
}else{ } else {
payload = { payload = {
geom: null, geom: null,
} }
} }
$.ajax({ $.ajax({
data: JSON.stringify(payload), data: JSON.stringify(payload),
url: `${base_url}task/update-regular/${currentIdAct}`, url: `${base_url}task/update-regular/${currentIdAct}`,
type: "PUT", type: "PUT",
processData: false, processData: false,
contentType: false, contentType: false,
success: function (data) { success: function (data) {
$("#modal_activity_location").modal("hide"); $("#modal_activity_location").modal("hide");
currentGeoJson ="" currentGeoJson = ""
currentIdAct = 0; currentIdAct = 0;
gantt.alert("Activity Location successfully updated!"); gantt.alert("Activity Location successfully updated!");
}, },
error: function (data) { error: function (data) {
$("#modal_activity_location").modal("hide"); $("#modal_activity_location").modal("hide");
currentGeoJson ="" currentGeoJson = ""
currentIdAct = 0; currentIdAct = 0;
gantt.alert("Activity Location failed updated!, try again later!"); gantt.alert("Activity Location failed updated!, try again later!");
} }
}); });
} }
$("#modal_radius").on("click", "#btn_save_radius", function() { $("#modal_radius").on("click", "#btn_save_radius", function () {
let radius = $("#buffer_radius").val(); let radius = $("#buffer_radius").val();
if(radius <= 0){ if (radius <= 0) {
gantt.alert("radius buffer tidak boleh kurang dari atau sama dengan 0!!"); gantt.alert("radius buffer tidak boleh kurang dari atau sama dengan 0!!");
}else{ } else {
submitCircle(radius); submitCircle(radius);
} }
}); });
}); });
function submitCircle(radius) function submitCircle(radius) {
{ let circle = L.circle([circLat, circLong], { radius: radius });
let circle = L.circle([circLat,circLong], {radius: radius});
let geojsoncircle = circle.toGeoJSON(); let geojsoncircle = circle.toGeoJSON();
geojsoncircle.properties.radius = radius geojsoncircle.properties.radius = radius
currentGeoJson = geojsoncircle currentGeoJson = geojsoncircle
// console.log("geojsoncircle", geojsoncircle);
addDrawnLayer(circle); addDrawnLayer(circle);
updateCurrentGeoJson();
map.addControl(drawnControlEdit); map.addControl(drawnControlEdit);
$("#modal_radius").modal('hide'); $("#modal_radius").modal('hide');
} }
$('#modal_radius').on('hide.bs.modal', function (event) { $('#modal_radius').on('hide.bs.modal', function (event) {
circLat = 0 circLat = 0
circLong = 0 circLong = 0
$("#buffer_radius").val(""); $("#buffer_radius").val("");
}); });

45
edit-mode/function/ganttConfig.js

@ -285,19 +285,6 @@ var allColumns = [
return text.planned_start; return text.planned_start;
} }
}, },
// {
// name: "early_start", label: "Early Start", align: "center", min_width: 80, editor: editor.early_start, resize: true, template: function (text) {
// let siblingId = gantt.getPrevSibling(text.id);
// if(siblingId){
// let tempText = gantt.getTask(siblingId);
// console.log("iddd ", gantt.getTask(siblingId));
// return moment(tempText.end_date).format('YYYY-MM-DD');
// }
// return text.planned_start;
// }
// },
{ name: "early_start", label: "Early Start", align: "center", min_width: 80, editor: editor.early_start, resize: true },
{ name: "start_date", label: "Actual Start", align: "center", min_width: 80, editor: editor.start_date, resize: true },
{ {
name: "planned_end", label: "Baseline Finish", align: "center", min_width: 80, editor: editor.planned_end, resize: true, template: function (text) { name: "planned_end", label: "Baseline Finish", align: "center", min_width: 80, editor: editor.planned_end, resize: true, template: function (text) {
if (!text.planned_end) { if (!text.planned_end) {
@ -306,25 +293,11 @@ var allColumns = [
return text.planned_end; return text.planned_end;
} }
}, },
// { name: "early_end", label: "Early Finish", align: "center", min_width: 80, editor: editor.early_end, resize: true }, { name: "start_date", label: "Early Start", align: "center", min_width: 80, editor: editor.start_date, resize: true },
// { { name: "end_date", label: "Early Finish", align: "center", min_width: 80, editor: editor.end_date, resize: true },
// name: "early_end", label: "Early Finish", align: "center", min_width: 80, editor: editor.early_end, resize: true, template: function (text) {
// let start;
// let end;
// text.planned_start ? start = text.planned_start : start = text.start_date;
// text.planned_end ? end = text.planned_end : end = text.end_date;
// let plannedDuration = gantt.calculateDuration({
// start_date: new Date(start),
// end_date: new Date(end)
// })
// return moment(text.start_date).add(plannedDuration-1, 'days').format('YYYY-MM-DD');
// // return text.planned_end;
// }
// },
{ name: "early_end", label: "Early Finish", align: "center", min_width: 80, resize: true },
{ name: "end_date", label: "Actual Finish", align: "center", min_width: 80, resize: true },
{ name: "actual_start", label: "Actual Start", align: "center", min_width: 80, resize: true },
{ name: "actual_end", label: "Actual Finish", align: "center", min_width: 80, resize: true },
{ {
name: "bobot_planning", label: "Bobot (%)", align: "center", editor: editor.bobot_planning, resize: true, min_width: 115, template: function (text) { name: "bobot_planning", label: "Bobot (%)", align: "center", editor: editor.bobot_planning, resize: true, min_width: 115, template: function (text) {
let bobot = parseFloat(text.bobot_planning); let bobot = parseFloat(text.bobot_planning);
@ -381,7 +354,7 @@ var allColumns = [
}) })
return plannedDuration; return plannedDuration;
}}, }},
{ name: "duration", label: "Actual Duration (Day)", align: "center", min_width: 50, resize: true, editor: editor.duration }, { name: "duration", label: "Duration (Day)", align: "center", min_width: 50, resize: true, editor: editor.duration },
{ {
name: "rencana_biaya", label: "Cost Planning", align: "right", min_width: 100, resize: true, template: function (text) { name: "rencana_biaya", label: "Cost Planning", align: "right", min_width: 100, resize: true, template: function (text) {
if (!text.rencana_biaya) { if (!text.rencana_biaya) {
@ -549,8 +522,8 @@ let columnShows = {
planned_start: false, planned_start: false,
planned_end: false, planned_end: false,
planned_duration: false, planned_duration: false,
early_start: false, actual_start: false,
early_end: false, actual_end: false,
duration: true, duration: true,
rencana_biaya: true, rencana_biaya: true,
cost_actual: true, cost_actual: true,
@ -577,8 +550,8 @@ gantt.config.columns = createColumnsConfig({
planned_start: true, planned_start: true,
planned_end: true, planned_end: true,
planned_duration: true, planned_duration: true,
early_start: true, actual_start: true,
early_end: true, actual_end: true,
duration: true, duration: true,
rencana_biaya: true, rencana_biaya: true,
cost_actual: true, cost_actual: true,

Loading…
Cancel
Save