267 lines
9.7 KiB
JavaScript
267 lines
9.7 KiB
JavaScript
app.controller('masterScenarioCalendarController', ['$scope', '$http', '$location', '$timeout', function ($scope, $http, $location, $timeout) {
|
|
$scope.collapsedIcon = 'fa-plus-square';
|
|
$scope.nonCollapsedIcon = 'fa-minus-square';
|
|
|
|
$scope.GraphIsDisabled = true;
|
|
$scope.calendarFilters = {
|
|
IsTableModeQuantity: true,
|
|
ShowActuals: false,
|
|
IsViewModeMonth: true,
|
|
IsUOMHours: null,
|
|
ProjectId: null
|
|
};
|
|
|
|
$scope.$watch('calendarFilters.IsUOMHours', function (oldValue, newValue) {
|
|
if (oldValue != newValue) {
|
|
savePagePreferences();
|
|
$scope.getCalendar();
|
|
}
|
|
});
|
|
$scope.$watch('calendarFilters.IsTableModeQuantity', function (oldValue, newValue) {
|
|
if (oldValue != newValue) {
|
|
savePagePreferences();
|
|
}
|
|
});
|
|
$scope.$watch('calendarFilters.IsViewModeMonth', function (oldValue, newValue) {
|
|
if (oldValue != newValue) {
|
|
savePagePreferences();
|
|
$scope.switchViewMode();
|
|
}
|
|
});
|
|
$scope.$watch('calendarFilters.ShowActuals', function (oldValue, newValue) {
|
|
if (oldValue != newValue) {
|
|
$scope.getCalendar();
|
|
}
|
|
});
|
|
$scope.init = function (data) {
|
|
if (!data)
|
|
return;
|
|
|
|
$scope.calendarFilters.ProjectId = data.ProjectId;
|
|
if (data.PagePreferences && data.PagePreferences.length > 0) {
|
|
var pagePrefArray = JSON.parse(data.PagePreferences);
|
|
|
|
for (var i = 0; i < pagePrefArray.length; i++) {
|
|
switch (pagePrefArray[i].Key) {
|
|
case "uomMode":
|
|
$scope.calendarFilters.IsUOMHours = pagePrefArray[i].Value;
|
|
break;
|
|
case "chMode":
|
|
$scope.calendarFilters.IsTableModeQuantity = pagePrefArray[i].Value;
|
|
break;
|
|
case "monthWeekMode":
|
|
$scope.calendarFilters.IsViewModeMonth = pagePrefArray[i].Value;
|
|
break;
|
|
default:
|
|
console.log("Restore page preferences (Master Scenario Details): data key not found in parsing loaded preferences (datakey=" +
|
|
pagePrefArray[i].Key + ", dataSection=" + data.DataSection + ")");
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($scope.calendarFilters.IsUOMHours == null || $scope.calendarFilters.IsUOMHours == undefined)
|
|
$scope.calendarFilters.IsUOMHours = data.IsUOMHours;
|
|
|
|
$scope.getCalendar();
|
|
};
|
|
$scope.getCalendar = function () {
|
|
$scope.data = null;
|
|
blockUI();
|
|
|
|
var data = {
|
|
ProjectId: $scope.calendarFilters.ProjectId,
|
|
IsUOMHours: $scope.calendarFilters.IsUOMHours,
|
|
ShowActuals: $scope.calendarFilters.ShowActuals
|
|
};
|
|
|
|
$http.post('/Scenarios/GetMasterScenarioCalendar', JSON.stringify(data))
|
|
.success(function (data, status, headers, config) {
|
|
if (!data || !data.Headers || data.Headers.length < 1) {
|
|
unblockUI();
|
|
return;
|
|
}
|
|
$scope.data = data;
|
|
|
|
$scope.switchViewMode();
|
|
|
|
unblockUI();
|
|
})
|
|
.error(function (data, status, headers, config) {
|
|
console.log("an error occurred while loading master scenario calendar");
|
|
unblockUI();
|
|
});
|
|
}
|
|
$scope.onMonthHeaderClick = function (header) {
|
|
header.Collapsed = !header.Collapsed;
|
|
header.Show = !header.Show;
|
|
header.CollapsedClass = header.Collapsed ? $scope.collapsedIcon : $scope.nonCollapsedIcon;
|
|
if (header.Weeks && header.Weeks.length > 0)
|
|
for (var i = 0; i < header.Weeks.length; i++) {
|
|
$scope.data.Headers[header.Weeks[i]].Collapsed = header.Collapsed;
|
|
$scope.data.Headers[header.Weeks[i]].Show = !header.Collapsed;
|
|
}
|
|
$scope.resizeFreezAng();
|
|
}
|
|
|
|
$scope.checkRow = function (row) {
|
|
if (!row) {
|
|
return;
|
|
}
|
|
|
|
row.Checked = !row.Checked;
|
|
|
|
$scope.applyChecked();
|
|
};
|
|
|
|
$scope.checkAll = function () {
|
|
if (!$scope.data || !$scope.data.ScenarioCalendar || !Object.keys($scope.data.ScenarioCalendar).length) {
|
|
return;
|
|
}
|
|
|
|
$scope.data.ScenarioCalendar[0].Checked = !$scope.data.ScenarioCalendar[0].Checked;
|
|
if (!$scope.data || !$scope.data.ScenarioCalendar) {
|
|
return;
|
|
}
|
|
|
|
for (var i = 1; i < $scope.data.ScenarioCalendar.length; i++) {
|
|
$scope.data.ScenarioCalendar[i].Checked = $scope.data.ScenarioCalendar[0].Checked;
|
|
}
|
|
|
|
$scope.GraphIsDisabled = getCheckedExpendituresCount() <= 0;
|
|
};
|
|
|
|
$scope.onExpCatClick = function (row) {
|
|
// skip collapsing in actuals mode
|
|
if ($scope.calendarFilters.ShowActuals)
|
|
return;
|
|
|
|
row.Collapsed = !row.Collapsed;
|
|
row.CollapsedClass = row.Collapsed ? $scope.collapsedIcon : $scope.nonCollapsedIcon;
|
|
};
|
|
|
|
$scope.resizeFreezAng = function () {
|
|
setTimeout(function () {
|
|
resizeFreez('master-scenario-table');
|
|
}, 0);
|
|
};
|
|
|
|
$scope.applyChecked = function () {
|
|
if (!$scope.data || !$scope.data.ScenarioCalendar || !Object.keys($scope.data.ScenarioCalendar).length) {
|
|
return;
|
|
}
|
|
|
|
var checkedRowsCount = getCheckedExpendituresCount();
|
|
|
|
$scope.data.ScenarioCalendar[0].Checked = (checkedRowsCount > 0 && checkedRowsCount === ($scope.data.ScenarioCalendar.length - 1));
|
|
$scope.GraphIsDisabled = checkedRowsCount <= 0;
|
|
};
|
|
|
|
$scope.switchViewMode = function () {
|
|
for (var i = 0; i < $scope.data.Headers.length; i++) {
|
|
if ($scope.data.Headers[i].IsMonth) {
|
|
$scope.data.Headers[i].Collapsed = $scope.calendarFilters.IsViewModeMonth;
|
|
$scope.data.Headers[i].Show = $scope.calendarFilters.IsViewModeMonth;
|
|
$scope.data.Headers[i].CollapsedClass = $scope.calendarFilters.IsViewModeMonth ? $scope.collapsedIcon : $scope.nonCollapsedIcon;
|
|
} else {
|
|
$scope.data.Headers[i].Collapsed = $scope.calendarFilters.IsViewModeMonth;
|
|
$scope.data.Headers[i].Show = !$scope.calendarFilters.IsViewModeMonth;
|
|
}
|
|
}
|
|
$scope.resizeFreezAng();
|
|
};
|
|
|
|
$scope.graphData = [];
|
|
$scope.maxGraphValue = 0;
|
|
$scope.showGraph = function () {
|
|
// prepare data
|
|
$scope.maxGraphValue = 0;
|
|
$scope.graphData = [];
|
|
|
|
var startDate = new Date($scope.data.StartDate);
|
|
var endDate = new Date($scope.data.EndDate);
|
|
var days = (endDate - startDate) / (1000 * 60 * 60 * 24);
|
|
var i;
|
|
|
|
for (i = 1; i < $scope.data.ScenarioCalendar.length; i++) {
|
|
// skip this row if it is not checked
|
|
if (!$scope.data.ScenarioCalendar[i].Checked)
|
|
continue;
|
|
|
|
var expCatData = new Array();
|
|
for (var colIndex = 0; colIndex < $scope.data.Headers.length; colIndex++) {
|
|
if ($scope.data.Headers[colIndex].IsMonth)
|
|
continue;
|
|
expCatData[expCatData.length] = [$scope.data.Headers[colIndex].Milliseconds, $scope.data.ScenarioCalendar[i].QuantityValues[colIndex]];
|
|
if (true !== $scope.calendarFilters.IsTableModeQuantity) {
|
|
expCatData[expCatData.length - 1][1] = $scope.data.ScenarioCalendar[i].CostValues[colIndex];
|
|
}
|
|
if (expCatData[expCatData.length - 1][1] > $scope.maxGraphValue)
|
|
$scope.maxGraphValue = expCatData[expCatData.length - 1][1];
|
|
expCatData[expCatData.length - 1][1] = expCatData[expCatData.length - 1][1].toFixed(2);
|
|
}
|
|
$scope.graphData[$scope.graphData.length] = {
|
|
label: $scope.data.ScenarioCalendar[i].ExpCatName,
|
|
data: expCatData,
|
|
lines: { show: true, fill: true, steps: false },
|
|
filledPoints: true,
|
|
stack: true
|
|
};
|
|
}
|
|
|
|
$timeout(function () {
|
|
$scope.initGraph()
|
|
});
|
|
};
|
|
$scope.initGraph = function () {
|
|
// Init Chart
|
|
$('#DetailsGraphContainer').html('<div id="divDetailsGraph"></div>');
|
|
$("#modalGraph").modal("show");
|
|
|
|
// SA. ENV-574
|
|
var C_MAX_GRAPH_TICK_LABELS = 8;
|
|
var maxSeriePoints = 0;
|
|
|
|
if ($scope.graphData && $scope.graphData.length > 0) {
|
|
|
|
$.each($scope.graphData, function (index, data) {
|
|
if (data.data && (data.data.length > 0)) {
|
|
maxSeriePoints = Math.max(maxSeriePoints, data.data.length);
|
|
}
|
|
});
|
|
}
|
|
|
|
var tickStep = Math.round((maxSeriePoints / 4) / C_MAX_GRAPH_TICK_LABELS);
|
|
tickStep = (tickStep > 0) ? tickStep : 1;
|
|
|
|
$('#divDetailsGraph').pixelPlot($scope.graphData, {
|
|
series: {
|
|
points: {
|
|
show: false
|
|
},
|
|
lines: {
|
|
show: true,
|
|
}
|
|
},
|
|
xaxis: {
|
|
mode: "time",
|
|
tickSize: [tickStep, "month"]
|
|
}
|
|
}, {
|
|
height: 405,
|
|
width: 405,
|
|
tooltipText: "y + ' units at ' + (new Date(x)).toString()"
|
|
});
|
|
};
|
|
var getCheckedExpendituresCount = function () {
|
|
if (!$scope.data || !$scope.data.ScenarioCalendar) {
|
|
return 0;
|
|
}
|
|
|
|
var checkedRows = $scope.data.ScenarioCalendar.filter(function (item) {
|
|
return !!item.ExpCatId && !isGuidEmpty(item.ExpCatId) && item.Checked;
|
|
});
|
|
var rowsCount = checkedRows.length;
|
|
|
|
return rowsCount;
|
|
};
|
|
}]); |