Commit 9a568d0b authored by Vladimir Baranov's avatar Vladimir Baranov

rref #5385. Add directive for Classroom Timetabling

parent b444025f
......@@ -484,13 +484,8 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
}
};
})
/**
* @memberof ulakbus.crud
* @ngdoc directive
* @name crudTimetableDirective
* @description directive for displaying timetable widget
*/
.directive("crudTimetableDirective", function(WSOps, $q){
.controller("crudTimetableDirectiveCtrl", function($scope, WSOps, $q){
// todo: replace with utils service method
function groupBy (list, propName) {
return list.reduce(function(acc, item) {
......@@ -498,71 +493,132 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
return acc;
}, {});
};
$scope.groupBy = groupBy;
function get_wf(scope, data){
data.token = scope.token;
data.wf = scope.wf;
$scope.get_wf = function get_wf(data){
var fieldName = $scope.mainFieldName || 'ogretim_elemani_zt';
data.token = $scope.token;
data.wf = $scope.wf;
return WSOps.request(data).then(function(result){
if (result.ogretim_elemani_zt){
if (result[fieldName]){
return result;
} else {
Generator.pathDecider(result.client_cmd || ['list'], scope, result);
// prevent result processing
return $q.reject();
}
Generator.pathDecider(result.client_cmd || ['list'], $scope, result);
// prevent result processing
return $q.reject();
}).then(function(result){
scope.message = result.msgbox;
return result.ogretim_elemani_zt
$scope.message = result.notification;
return result[fieldName]
})
}
$scope.prepareTimetable = function prepareTimetable(timetable){
var grouped = groupBy(timetable, "saat");
for (var day in grouped){
var dayItems = grouped[day];
grouped[day] = dayItems.sort(function(a, b){
return a.gun < b.gun ? -1 : 1;
});
}
var acc = [];
for (var t in grouped){
if (grouped.hasOwnProperty(t)){
acc.push([t, grouped[t]]);
}
}
return acc.sort(function(a, b){
return a[0] > b[0] ? 1 : -1;
});
}
})
.directive("crudTimetableDirective", function(){
return {
templateUrl: 'components/crud/templates/timetable.html',
restrict: 'E',
replace: true,
controller: 'crudTimetableDirectiveCtrl',
link: function(iScope, iElem, iAtrrs){
var mainFieldName = 'ogretim_elemani_zt';
iScope.mainFieldName = mainFieldName;
iScope.tablesList = iScope[mainFieldName].ogretim_elemanlari;
iScope.widgetTitle = "Öğretim Elemanı Zaman Tablosu"
iScope.lecturerList = iScope.ogretim_elemani_zt.ogretim_elemanlari;
initLecturer(iScope.ogretim_elemani_zt);
iScope.availableStates = [
{value: 1, name: "Uygun"},
{value: 2, name: "Belirsiz"},
{value: 3, name: "Meşgul"}
];
initLecturer(iScope[mainFieldName]);
function initLecturer(data){
iScope.currentLecturer = {
iScope.currentTable = {
key: data.oe_key,
name: data.name,
avatar_url: data.avatar_url,
totalHours: data.toplam_ders_saati
};
prepareTimetable(data.uygunluk_durumu);
iScope.timetable = iScope.prepareTimetable(data.uygunluk_durumu);
};
function prepareTimetable(timetable){
var grouped = groupBy(timetable, "saat");
for (var day in grouped){
var dayItems = grouped[day];
grouped[day] = dayItems.sort(function(a, b){
return a.gun < b.gun ? -1 : 1;
});
}
var acc = [];
for (var t in grouped){
if (grouped.hasOwnProperty(t)){
acc.push([t, grouped[t]]);
iScope.selectTable = function(lecturer){
iScope.loadingTable = true;
iScope.get_wf({
cmd: 'personel_sec',
secili_og_elemani: {key: lecturer.key}
}).then(function(response){
initLecturer(response);
}).finally(function(){
iScope.loadingTable = false;
})
};
iScope.changeValue = function(time){
iScope.loadingAction = true;
iScope.get_wf({
cmd: 'degistir',
change: {
'key': time.key,
'durum': time.durum
}
}
iScope.timetable = acc.sort(function(a, b){
return a[0] > b[0] ? 1 : -1;
});
}).then(function(table){
var days = table.uygunluk_durumu;
// update durum value from the response
for (var i=0; i<days.length; i++){
if (days[i].key == time.key){
time.durum = days[i].durum;
break;
}
}
}).finally(function(){
iScope.loadingAction = false;
})
}
}
}
})
.directive("crudTimetableDirective2", function(){
return {
templateUrl: 'components/crud/templates/timetable.html',
restrict: 'E',
replace: true,
controller: 'crudTimetableDirectiveCtrl',
link: function(iScope, iElem, iAtrrs){
var mainFieldName = 'derslik_zaman_tablosu';
iScope.mainFieldName = mainFieldName;
iScope.tablesList = iScope[mainFieldName].derslikler;
iScope.widgetTitle = "Derslik Zaman Tablosu";
initTable(iScope[mainFieldName]);
function initTable(data){
iScope.currentTable = {
key: data.oe_key,
name: data.name,
avatar_url: data.avatar_url
};
iScope.timetable = iScope.prepareTimetable(data.zaman_plani);
};
iScope.selectLecturer = function(lecturer){
iScope.selectTable = function(lecturer){
iScope.loadingTable = true;
get_wf(iScope, {
iScope.get_wf({
cmd: 'personel_sec',
secili_og_elemani: {key: lecturer.key}
}).then(function(response){
......@@ -574,7 +630,7 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
iScope.changeValue = function(time){
iScope.loadingAction = true;
get_wf(iScope, {
iScope.get_wf({
cmd: 'degistir',
change: {
'key': time.key,
......
......@@ -2,13 +2,13 @@
<div class="col-md-12 course-prg-scheduler">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">Course Scheduler Widget</div>
<div class="panel-title">{{widgetTitle}}</div>
</div>
<div class="panel-body">
<div class="col-xs-3"> <!-- required for floating -->
<div class="col-xs-3 tabs-container"> <!-- required for floating -->
<ul class="tabs-left">
<li ng-repeat="lecturer in lecturerList" ng-click="selectLecturer(lecturer)" ng-class="{active: currentLecturer.key == lecturer.key}"><a>{{lecturer.name}}</a></li>
<li ng-repeat="table in tablesList" ng-click="selectTable(table)" ng-class="{active: currentTable.key == table.key}"><a>{{table.name}}</a></li>
</ul>
</div>
......@@ -17,43 +17,43 @@
<!-- Tab panes -->
<div class="tab-content" ng-hide="loadingTable">
<div class="tab-pane active" id="one">
<div class="tab-pane active">
<div class="info-header clearfix">
<div class="info-wrapper">
<img ng-src="{{currentLecturer.avatar_url}}" class="profile-pic">
<span class="user-name">{{currentLecturer.name}}</span>
<img ng-src="{{currentTable.avatar_url}}" class="profile-pic" ng-show="currentTable.avatar_url">
<span class="user-name">{{currentTable.name}}</span>
</div>
<div class="info-wrapper info-wrapper_hours">
<span class="info-title">Ders Yükü:</span> <span>{{currentLecturer.totalHours}} saat</span>
<div class="info-wrapper info-wrapper_hours" ng-show="currentTable.totalHours">
<span class="info-title">Ders Yükü:</span> <span>{{currentTable.totalHours}} saat</span>
</div>
</div>
<!-- end of header -->
<div class="table-warning" ng-show="message">
<span class="glyphicon glyphicon-exclamation-sign"></span> {{message.title}}<br/>{{message.msg}}
<span class="glyphicon glyphicon-exclamation-sign"></span> {{message.message}}
</div>
<div class="table-container">
<table>
<tbody>
<tr class="headers">
<td></td>
<td>PZT</td>
<td>SAL</td>
<td>ÇAR</td>
<td>PER</td>
<td>CUM</td>
<td>CMT</td>
<td>PAZ</td>
</tr>
<tr ng-repeat="time in timetable">
<td>{{time[0]}}</td>
<td ng-repeat="day in time[1]">
<div timetable-action-selector ng-model="day.durum" readonly="{{currentTable.readonly}}" ng-change="changeValue(day)"></div>
</td>
</tr>
</tbody>
</table>
</div>
<table border="1">
<tbody>
<tr class="headers">
<td></td>
<td>PZT</td>
<td>SAL</td>
<td>ÇAR</td>
<td>PER</td>
<td>CUM</td>
<td>CMT</td>
<td>PAZ</td>
</tr>
<tr ng-repeat="time in timetable">
<td>{{time[0]}}</td>
<td ng-repeat="day in time[1]">
<div timetable-action-selector ng-model="day.durum" ng-change="changeValue(day)"></div>
</td>
</tr>
</tbody>
</table>
<div class="loader pull-right" ng-show="loadingAction">Loading...</div>
<ul class="legend">
<li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment