Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bfc040f7
authored
Oct 05, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on issue #526
parent
2b38048b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
411 additions
and
0 deletions
sails/src/assets/scripts/modules/supervisor/controllers/instructions.js
sails/src/assets/scripts/modules/supervisor/views/instructions.html
sails/src/assets/scripts/modules/supervisor/controllers/instructions.js
0 → 100644
View file @
bfc040f7
'use strict'
;
//-----------------------
// Student Instructions Controller
//-----------------------
dashboardControllers
.
controller
(
'StudentInstructionsCtrl'
,
function
StudentInstructionsCtrl
(
$scope
,
$stateParams
,
$http
,
config
,
$window
,
$translate
,
$modal
,
ngToast
,
newconfirm
)
{
// For tab navigation (here too, if the user refresh the page...)
$scope
.
nav
.
tab
=
'instructions'
;
// ----------------------------------------------------------------------
// METHODS
// Load student methods and instructions
//
//
//
// Array with methods available in meta_methods
//
$scope
.
methods_available
=
[];
// Query to meta_methods to fill the select fill with precharged methods
// and supervisor template methods
$http
.
get
(
config
.
backend
+
'/metamethods/'
+
$scope
.
user
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
// Add to list
$scope
.
methods_available
=
data
;
console
.
log
(
"Meta Methods charged:"
);
console
.
log
(
JSON
.
stringify
(
$scope
.
methods_available
));
// Option to add new methods
$scope
.
methods_available
.
push
({
id
:
0
,
name
:
"Nuevo método"
});
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
//
// Array with student methods (with instructions)
//
$scope
.
methods
=
[];
// Query to obtain an array of student methods
$http
.
get
(
config
.
backend
+
'/stu/'
+
$scope
.
studentData
.
id
+
'/methods'
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
// Add to list
$scope
.
methods
=
data
;
console
.
log
(
JSON
.
stringify
(
$scope
.
methods
));
console
.
log
(
"Methods recovered"
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
//
// Get last method/instruction for this student
//
/* $http
.get(config.backend+'/stu/'+ $scope.studentData.id +'/last_instruction')
.success(function(data, status, headers, config) {
$scope.studentData.current_method = data.met_name;
$scope.studentData.current_instruction = data.ins_name;
console.log('Last method/instruction:' + JSON.stringify(data));
})
.error(function(data, status, headers, config) {
console.log('Last method/instruction error:' + JSON.stringify(data));
$scope.studentData.current_method = 'undefined';
$scope.studentData.current_instruction = 'undefined';
});*/
// Add method selected to the student
$scope
.
add_method
=
function
(){
// Create a new method
if
(
$scope
.
method_selected
.
id
==
0
){
$http
.
post
(
config
.
backend
+
'/method/new'
,
{
'id_stu'
:
$scope
.
studentData
.
id
,
'name'
:
"Nuevo método (cambiar nombre)"
})
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
// Add empty array of instructions
data
.
instructions
=
[];
console
.
log
(
'Created new empty Method:'
+
JSON
.
stringify
(
data
));
$scope
.
methods
.
unshift
(
data
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
}
else
{
// Add method from templates
$http
.
post
(
config
.
backend
+
'/method'
,
{
'id_mmethod'
:
$scope
.
method_selected
.
id
,
'id_stu'
:
$scope
.
studentData
.
id
})
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Created Method and Instructions'
);
console
.
log
(
'Method (with Instructions):'
+
JSON
.
stringify
(
data
));
$scope
.
methods
.
push
(
data
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
console
.
log
(
$scope
.
method_selected
.
id
+
" "
+
$scope
.
studentData
.
id
);
});
}
};
// Delete template
$scope
.
delete_template
=
function
(){
$translate
(
'confirmation'
).
then
(
function
(
translation
)
{
newconfirm
(
translation
).
then
(
function
()
{
if
(
$scope
.
method_selected
.
supervisor
==
$scope
.
user
.
id
){
$http
.
delete
(
config
.
backend
+
'/method/template/'
+
$scope
.
method_selected
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Delete Method Template and its Instructions'
);
ngToast
.
success
({
content
:
$translate
.
instant
(
'template_deleted'
)});
// Delete in select
for
(
var
i
=
0
;
i
<
$scope
.
methods_available
.
length
;
i
++
)
{
if
(
$scope
.
methods_available
[
i
].
id
==
$scope
.
method_selected
.
id
){
$scope
.
methods_available
.
splice
(
i
,
1
);
$scope
.
method_selected
=
null
;
break
;
}
}
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
}
});
});
};
// Update method
$scope
.
update_method
=
function
(
method
){
// Remove instructions as we only update title or description
var
method_to_save
=
{};
Object
.
assign
(
method_to_save
,
method
);
delete
method_to_save
.
instructions
;
$http
.
put
(
config
.
backend
+
'/method/'
+
method
.
id
,
method_to_save
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Updated method:'
+
JSON
.
stringify
(
data
));
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
JSON
.
stringify
(
data
));
});
};
// Save method and its instructions as template in metamethods and metainstructions
$scope
.
save_as_template
=
function
(
method
){
$http
.
post
(
config
.
backend
+
'/method/save'
,
{
'id_met'
:
method
.
id
,
'id_sup'
:
$scope
.
user
.
id
})
.
then
(
//success
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Saved method as template:'
+
JSON
.
stringify
(
data
));
// Add to select method
$scope
.
methods_available
.
push
({
id
:
method
.
id
,
name
:
method
.
name
});
ngToast
.
success
({
content
:
$translate
.
instant
(
'method_saved'
,
{
method_name
:
method
.
name
}),
timeout
:
6000
// By default 4000
});
}
,
function
(
data
,
status
,
headers
,
config
)
{
//error
console
.
log
(
"Error from API: "
+
data
.
error
+
"("
+
data
.
status
+
")"
);
ngToast
.
success
({
content
:
$translate
.
instant
(
'method_name_duplicated'
,
{
method_name
:
method
.
name
}),
timeout
:
6000
// By default 4000
});
}
);
};
// Delete method t and its instructions
$scope
.
delete_method
=
function
(
method
){
$translate
(
'confirmation'
).
then
(
function
(
translation
)
{
newconfirm
(
translation
).
then
(
function
()
{
$http
.
delete
(
config
.
backend
+
'/method/'
+
method
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Delete Method and its Instructions'
);
console
.
log
(
'Method (with Instructions):'
+
JSON
.
stringify
(
data
));
// Delete in view
for
(
var
i
=
0
;
i
<
$scope
.
methods
.
length
;
i
++
)
{
if
(
$scope
.
methods
[
i
].
id
==
method
.
id
){
$scope
.
methods
.
splice
(
i
,
1
);
break
;
}
}
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
ngToast
.
warning
({
content
:
$translate
.
instant
(
'cannot_delete_method'
),
timeout
:
6000
// By default 4000
});
});
});
});
};
// Add instruction
$scope
.
add_instruction
=
function
(
method
){
$http
.
post
(
config
.
backend
+
'/instruction'
,
{
method
:
method
.
id
}
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Added instruction:'
+
JSON
.
stringify
(
data
));
// Add in view
method
.
instructions
.
push
(
data
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
};
// Update instruction of a method
$scope
.
update_instruction
=
function
(
ins
){
$http
.
put
(
config
.
backend
+
'/instruction/'
+
ins
.
id
,
ins
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Updated instruction:'
+
JSON
.
stringify
(
data
));
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
};
// Change the status of an instruction (and update)
$scope
.
change_status
=
function
(
ins
){
if
(
ins
.
status
==
null
)
ins
.
status
=
"started"
;
else
if
(
ins
.
status
==
"started"
)
ins
.
status
=
"finished"
;
else
if
(
ins
.
status
==
"finished"
)
ins
.
status
=
null
;
// update the instruction with the new value
$scope
.
update_instruction
(
ins
);
};
// Delete instruction of a method
$scope
.
delete_instruction
=
function
(
ins
){
$http
.
delete
(
config
.
backend
+
'/instruction/'
+
ins
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Deleted instruction:'
+
JSON
.
stringify
(
data
));
// Buscar method
for
(
var
i
=
0
;
i
<
$scope
.
methods
.
length
;
i
++
)
{
var
m
=
$scope
.
methods
[
i
];
if
(
ins
.
method
==
m
.
id
){
// Buscar la instrucción y eliminar de la vista
for
(
var
j
=
0
;
j
<
m
.
instructions
.
length
;
j
++
)
{
if
(
ins
.
id
==
m
.
instructions
[
j
].
id
){
$scope
.
methods
[
i
].
instructions
.
splice
(
j
,
1
);
break
;
}
}
break
;
}
}
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
// Show message
ngToast
.
warning
({
content
:
$translate
.
instant
(
'cannot_delete_instruction'
),
timeout
:
6000
// By default 4000
});
});
};
// Modal window to open instruction details
$scope
.
open_instruction
=
function
(
ins
)
{
var
modalInstance
=
$modal
.
open
({
animation
:
true
,
templateUrl
:
'modules/student/views/instructiondetail.html'
,
controller
:
'InstructionDetailCtrl'
,
size
:
'md'
,
resolve
:
{
// Passing data to the controller of the window
instruction
:
function
(){
return
ins
;
}
}
});
// Returned data from the modal window
modalInstance
.
result
.
then
(
function
(
ins
)
{
// Output from the window by clicking cancel or outside its borders
console
.
log
(
"Modal dismissed: "
+
JSON
.
stringify
(
ins
));
}
);
};
// End Modal window to view instruction details
});
sails/src/assets/scripts/modules/supervisor/views/instructions.html
0 → 100644
View file @
bfc040f7
<!-- InstructionsCtrl controls here, see app.js -->
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
><h3
class=
"panel-title"
translate
>
students
</h3></div>
<div
class=
"panel-body"
>
<!-- Select to add new method -->
<div
class=
"form-group"
>
<select
class=
"form-control"
name=
"method_select"
id=
"method_select"
ng-model=
"method_selected"
ng-options=
"ma.name for ma in methods_available"
>
<option
value=
""
translate
>
select_method
</option>
</select>
<!-- Botón añadir método -->
<button
ng-click=
"add_method()"
class=
"btn btn-success btn-sm"
popover=
"{{ 'add' | translate}}"
popover-trigger=
"mouseenter"
ng-disabled=
"method_selected.id == undefined"
>
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
</button>
<!-- Botón eliminar plantilla -->
<button
ng-click=
"delete_template()"
class=
"btn btn-danger btn-sm"
popover=
"{{ 'delete_template' | translate}}"
popover-trigger=
"mouseenter"
ng-show=
"method_selected.supervisor == user.id"
>
<span
class=
"glyphicon glyphicon-minus"
aria-hidden=
"true"
></span>
</button>
</div>
<!-- END select to add new method -->
<!-- Method instructions -->
<div
class=
"method_details"
ng-repeat=
"m in methods"
>
<input
type=
"text"
class=
"editable title"
ng-model=
"m.name "
ng-blur=
"update_method(m)"
/>
<div
class=
"options"
>
<a
ng-click=
"save_as_template(m)"
popover=
"{{ 'save_as_template' | translate}}"
popover-trigger=
"mouseenter"
><span
class=
"text_medium color_black glyphicon glyphicon-floppy-disk"
aria-hidden=
"true"
></span></a>
<a
ng-click=
"delete_method(m)"
popover=
"{{ 'delete' | translate}}"
popover-trigger=
"mouseenter"
><span
class=
"text_medium delete color_red glyphicon glyphicon-remove-circle"
aria-hidden=
"true"
></span></a>
</div>
<textarea
class=
"editable"
ng-model=
"m.description "
placeholder=
"{{'description' | translate}}"
ng-blur=
"update_method(m)"
></textarea>
<!-- Tabla método -->
<table
class=
"table_instructions table"
>
<tr>
<th></th>
<th
translate
>
instruction
</th>
<th
translate
>
objetive
</th>
<th
class=
"text-center"
translate
>
instruction_begin
</th>
<th
class=
"text-center"
translate
>
instruction_end
</th>
<th
class=
"text-center"
translate
>
state
</th>
<th></th>
</tr>
<tr
ng-repeat=
"i in m.instructions"
>
<td>
<a
ng-click=
"open_instruction(i)"
><span
class=
"glyphicon glyphicon-file text_medium"
aria-hidden=
"true"
></span></a>
</td>
<td><input
class=
"editable"
type=
"text"
ng-model=
"i.name"
ng-blur=
"update_instruction(i)"
/></td>
<td><input
class=
"elipsis editable"
type=
"text"
ng-model=
"i.objective"
ng-blur=
"update_instruction(i)"
/></td>
<td
class=
"editable"
>
<div
class=
"text-center"
>
<span
class=
"color_blue"
>
{{ i.begin | date:"dd-MM-yyyy" }}
</span>
<br
/>
{{ i.begin | date:"HH:mm:ss" }}
</div>
</td>
<td
class=
"editable"
>
<div
class=
"text-center"
ng-class=
"{ color_green : i.id == m.last_ins }"
>
<span
ng-class=
"{ color_green : i.id == m.last_ins, color_blue : i.id != m.last_ins }"
>
{{ i.end | date:"dd-MM-yyyy" }}
</span>
<br/>
{{ i.end | date:"HH:mm:ss" }}
</div>
</td>
<td
class=
"editable_status"
>
<span
class=
"pointer text_medium glyphicon"
ng-class=
"{
'color_green': i.status == 'finished',
'glyphicon-check': i.status == 'finished',
'color_blue': i.status == 'started',
'glyphicon-edit': i.status == 'started',
'glyphicon-minus': i.status == null
}"
aria-hidden=
"true"
popover=
"{{(i.status || 'nobegin') | translate}}"
popover-trigger=
"mouseenter"
ng-click=
"change_status(i)"
></span>
</td>
<td><a
confirmed-click=
"delete_instruction(i);"
ng-confirm-click=
"{{ 'confirmation' | translate}}"
class=
"delete_instruction"
><span
class=
"text_medium delete color_red glyphicon glyphicon-remove-circle"
aria-hidden=
"true"
></span></a></td>
</tr>
</table>
<!-- Añadir instrucción al método -->
<p
class=
"text-right"
>
<a
ng-click=
"add_instruction(m)"
class=
"add_instruction btn btn-success btn-sm"
role=
"button"
>
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
{{ 'add_instruction' | translate }}
</a>
</p>
</div>
<!-- Fin de .method_details -->
</div>
<!-- END .panel-body -->
</div>
<!-- END .panel -->
</div>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment