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 ...@@ -484,13 +484,8 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
} }
}; };
}) })
/**
* @memberof ulakbus.crud .controller("crudTimetableDirectiveCtrl", function($scope, WSOps, $q){
* @ngdoc directive
* @name crudTimetableDirective
* @description directive for displaying timetable widget
*/
.directive("crudTimetableDirective", function(WSOps, $q){
// todo: replace with utils service method // todo: replace with utils service method
function groupBy (list, propName) { function groupBy (list, propName) {
return list.reduce(function(acc, item) { return list.reduce(function(acc, item) {
...@@ -498,71 +493,132 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi ...@@ -498,71 +493,132 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
return acc; return acc;
}, {}); }, {});
}; };
$scope.groupBy = groupBy;
function get_wf(scope, data){ $scope.get_wf = function get_wf(data){
data.token = scope.token; var fieldName = $scope.mainFieldName || 'ogretim_elemani_zt';
data.wf = scope.wf; data.token = $scope.token;
data.wf = $scope.wf;
return WSOps.request(data).then(function(result){ return WSOps.request(data).then(function(result){
if (result.ogretim_elemani_zt){ if (result[fieldName]){
return result; return result;
} else { }
Generator.pathDecider(result.client_cmd || ['list'], scope, result); Generator.pathDecider(result.client_cmd || ['list'], $scope, result);
// prevent result processing // prevent result processing
return $q.reject(); return $q.reject();
}
}).then(function(result){ }).then(function(result){
scope.message = result.msgbox; $scope.message = result.notification;
return result.ogretim_elemani_zt 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 { return {
templateUrl: 'components/crud/templates/timetable.html', templateUrl: 'components/crud/templates/timetable.html',
restrict: 'E', restrict: 'E',
replace: true, replace: true,
controller: 'crudTimetableDirectiveCtrl',
link: function(iScope, iElem, iAtrrs){ 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[mainFieldName]);
initLecturer(iScope.ogretim_elemani_zt);
iScope.availableStates = [
{value: 1, name: "Uygun"},
{value: 2, name: "Belirsiz"},
{value: 3, name: "Meşgul"}
];
function initLecturer(data){ function initLecturer(data){
iScope.currentLecturer = { iScope.currentTable = {
key: data.oe_key, key: data.oe_key,
name: data.name, name: data.name,
avatar_url: data.avatar_url, avatar_url: data.avatar_url,
totalHours: data.toplam_ders_saati totalHours: data.toplam_ders_saati
}; };
prepareTimetable(data.uygunluk_durumu); iScope.timetable = iScope.prepareTimetable(data.uygunluk_durumu);
}; };
function prepareTimetable(timetable){ iScope.selectTable = function(lecturer){
var grouped = groupBy(timetable, "saat"); iScope.loadingTable = true;
for (var day in grouped){ iScope.get_wf({
var dayItems = grouped[day]; cmd: 'personel_sec',
grouped[day] = dayItems.sort(function(a, b){ secili_og_elemani: {key: lecturer.key}
return a.gun < b.gun ? -1 : 1; }).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
} }
var acc = []; }).then(function(table){
for (var t in grouped){ var days = table.uygunluk_durumu;
if (grouped.hasOwnProperty(t)){ // update durum value from the response
acc.push([t, grouped[t]]); for (var i=0; i<days.length; i++){
if (days[i].key == time.key){
time.durum = days[i].durum;
break;
} }
} }
iScope.timetable = acc.sort(function(a, b){ }).finally(function(){
return a[0] > b[0] ? 1 : -1; 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; iScope.loadingTable = true;
get_wf(iScope, { iScope.get_wf({
cmd: 'personel_sec', cmd: 'personel_sec',
secili_og_elemani: {key: lecturer.key} secili_og_elemani: {key: lecturer.key}
}).then(function(response){ }).then(function(response){
...@@ -574,7 +630,7 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi ...@@ -574,7 +630,7 @@ angular.module('ulakbus.crud', ['schemaForm', 'ui.bootstrap', 'ulakbus.formServi
iScope.changeValue = function(time){ iScope.changeValue = function(time){
iScope.loadingAction = true; iScope.loadingAction = true;
get_wf(iScope, { iScope.get_wf({
cmd: 'degistir', cmd: 'degistir',
change: { change: {
'key': time.key, 'key': time.key,
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
<div class="col-md-12 course-prg-scheduler"> <div class="col-md-12 course-prg-scheduler">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<div class="panel-title">Course Scheduler Widget</div> <div class="panel-title">{{widgetTitle}}</div>
</div> </div>
<div class="panel-body"> <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"> <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> </ul>
</div> </div>
...@@ -17,24 +17,23 @@ ...@@ -17,24 +17,23 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content" ng-hide="loadingTable"> <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-header clearfix">
<div class="info-wrapper"> <div class="info-wrapper">
<img ng-src="{{currentLecturer.avatar_url}}" class="profile-pic"> <img ng-src="{{currentTable.avatar_url}}" class="profile-pic" ng-show="currentTable.avatar_url">
<span class="user-name">{{currentLecturer.name}}</span> <span class="user-name">{{currentTable.name}}</span>
</div> </div>
<div class="info-wrapper info-wrapper_hours"> <div class="info-wrapper info-wrapper_hours" ng-show="currentTable.totalHours">
<span class="info-title">Ders Yükü:</span> <span>{{currentLecturer.totalHours}} saat</span> <span class="info-title">Ders Yükü:</span> <span>{{currentTable.totalHours}} saat</span>
</div> </div>
</div> </div>
<!-- end of header --> <!-- end of header -->
<div class="table-warning" ng-show="message"> <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>
<div class="table-container">
<table border="1"> <table>
<tbody> <tbody>
<tr class="headers"> <tr class="headers">
<td></td> <td></td>
...@@ -49,11 +48,12 @@ ...@@ -49,11 +48,12 @@
<tr ng-repeat="time in timetable"> <tr ng-repeat="time in timetable">
<td>{{time[0]}}</td> <td>{{time[0]}}</td>
<td ng-repeat="day in time[1]"> <td ng-repeat="day in time[1]">
<div timetable-action-selector ng-model="day.durum" ng-change="changeValue(day)"></div> <div timetable-action-selector ng-model="day.durum" readonly="{{currentTable.readonly}}" ng-change="changeValue(day)"></div>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</div>
<div class="loader pull-right" ng-show="loadingAction">Loading...</div> <div class="loader pull-right" ng-show="loadingAction">Loading...</div>
<ul class="legend"> <ul class="legend">
<li> <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