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
59bc9458
authored
Oct 06, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #526 implemented
parent
88f6058f
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
99 additions
and
183 deletions
sails/src/api/controllers/MetaInstructionController.js
sails/src/api/controllers/MetaMethodController.js
sails/src/api/controllers/MethodController.js
sails/src/assets/app/i18n/en-gb.json
sails/src/assets/app/i18n/es-es.json
sails/src/assets/scripts/modules/student/controllers/instructions.js
sails/src/assets/scripts/modules/supervisor/controllers/instructions.js
sails/src/assets/scripts/modules/supervisor/views/instructions.html
sails/src/config/routes.js
sails/src/api/controllers/MetaInstructionController.js
View file @
59bc9458
...
...
@@ -29,7 +29,7 @@ module.exports = {
return
res
.
badRequest
();
MetaInstruction
.
create
({
method
:
method
.
id
,
id_met
:
method
.
id
,
name
:
req
.
param
(
'name'
),
objective
:
req
.
param
(
'objective'
),
})
...
...
@@ -78,7 +78,7 @@ module.exports = {
if
(
error
)
return
res
.
serverError
();
return
res
.
ok
(
instruction
);
}
}
);
})
.
catch
(
function
()
{
return
res
.
serverError
();
...
...
sails/src/api/controllers/MetaMethodController.js
View file @
59bc9458
...
...
@@ -10,128 +10,6 @@
module
.
exports
=
{
/**
* Creates a new method for a student using a template (metamethod)
* @param {request} req
* {
* id_mmethod: metaMethodId,
* id_stu: studentId
* }
* @param {response} res
* {
* id: methodId,
* name: 'MetaMethod Name',
* description: 'MetaMethod Description',
* instructions: [
* {
* id: instructionId,
* name: 'Instruction Name',
* objective: 'Instruction Objective',
* method: methodId
* },
* ...
* ]
* }
*/
create
:
function
(
req
,
res
)
{
var
params
=
req
.
allParams
();
if
(
!
params
.
id_mmethod
)
return
res
.
badRequest
(
"No meta method defined"
);
if
(
!
params
.
id_stu
)
return
res
.
badRequest
(
"No student defined"
);
// Find meta method
MetaMethod
.
findOne
({
id
:
params
.
id_mmethod
})
.
then
(
mmethod
=>
{
if
(
!
mmethod
)
throw
new
Error
(
"Meta method not found"
);
// Create new method by meta method
return
Method
.
create
(
{
name
:
mmethod
.
name
,
description
:
mmethod
.
description
,
student
:
params
.
id_stu
})
.
then
(
created
=>
created
)
.
fail
(
err
=>
{
throw
err
});
})
.
then
(
created
=>
{
// Find meta instructions associated to meta method
MetaInstruction
.
find
({
id_met
:
params
.
id_mmethod
})
.
then
(
minstructions
=>
{
if
(
!
minstructions
)
minstructions
=
[];
var
l_ins
=
[];
// Every meta instruction is going to be created in 'Instruction'
// with .eachSeries the order of resulting array will be equal
// to the original array
async
.
eachSeries
(
minstructions
,
function
(
mins
,
next
)
{
Instruction
.
create
({
method
:
created
.
id
,
name
:
mins
.
name
,
objective
:
mins
.
objective
})
.
then
(
added
=>
{
l_ins
.
push
(
added
);
sails
.
log
.
debug
(
"Instruction "
+
added
.
name
+
" added to method "
+
created
.
id
);
})
.
fail
(
err
=>
{
throw
err
})
.
done
(()
=>
{
next
()});
},
function
(
err
,
results
)
{
if
(
err
)
throw
new
Error
(
"Error while looping through instructions"
);
return
res
.
ok
({
"name"
:
created
.
name
,
"description"
:
created
.
description
,
"id"
:
created
.
id
,
"student"
:
created
.
id_stu
,
"instructions"
:
l_ins
});
});
})
.
fail
(
err
=>
{
throw
err
});
})
.
fail
(
err
=>
{
return
res
.
badRequest
(
err
);
});
},
/**
* Creates a new method from scratch (without using a template)
* @param {request} req
* {
* id_stu: studentId,
* name: 'Method name'
* }
* @param {response} res
* {
* id: methodId,
* student: studentId,
* name: 'Method name'
* }
*/
newMethod
:
function
(
req
,
res
)
{
if
(
req
.
param
(
'name'
)
&&
req
.
param
(
'id_stu'
))
{
Method
.
create
({
name
:
req
.
param
(
'name'
),
student
:
req
.
param
(
'id_stu'
)
}).
then
(
function
(
method
)
{
if
(
!
method
)
{
res
.
badRequest
();
throw
new
Error
(
'method not created'
);
}
res
.
ok
(
method
);
})
.
catch
(
function
()
{
res
.
serverError
();
});
}
else
{
res
.
badRequest
();
}
},
/**
* Return all the metamethods of a given supervisor (including the public metamethods)
* not associated to a concrete supervisor.
* @param {request} req {} (with idSup specified as url parameter)
...
...
@@ -188,11 +66,20 @@ module.exports = {
});
},
//
// Saves a new meta method (template)
//
save
:
function
(
req
,
res
){
/**
* Creates a new method from scratch (without using a template)
* @param {request} req
* {
* id_stu: studentId,
* name: 'Method name'
* }
* @param {response} res
* {
* id: methodId,
* name: 'Method name'
* }
*/
create
:
function
(
req
,
res
){
var
params
=
req
.
allParams
();
...
...
@@ -209,7 +96,35 @@ module.exports = {
})
.
catch
(
function
(
err
)
{
sails
.
log
.
debug
(
"Create Method template error: "
+
err
);
return
res
.
serverError
(
"Error creating method template"
);
return
res
.
serverError
(
err
);
});
},
//
// Updates a method template (just method, no instructions)
//
update
:
function
(
req
,
res
)
{
var
params
=
req
.
allParams
();
if
(
!
params
.
id
)
return
res
.
badRequest
(
"No template id specified"
);
MetaMethod
.
findOne
(
params
.
id
)
.
then
(
function
(
method
)
{
if
(
!
method
)
return
res
.
serverError
(
"No template found"
);
method
.
name
=
params
.
name
;
method
.
description
=
params
.
description
;
delete
method
.
metainstructions
;
method
.
save
(
function
(
err
)
{
if
(
err
)
return
res
.
serverError
(
err
);
return
res
.
ok
(
method
);
});
})
.
catch
(
function
(
err
)
{
sails
.
log
.
debug
(
"Error updating method"
+
err
.
msg
);
return
res
.
serverError
(
"Error updating method"
);
});
},
...
...
@@ -220,26 +135,27 @@ module.exports = {
var
params
=
req
.
allParams
();
if
(
!
params
.
id_mmet
)
{
if
(
!
params
.
id
)
{
return
res
.
badRequest
(
"No meta method defined"
);
}
// Destroy instructions
MetaInstruction
.
destroy
({
id_met
:
params
.
id_mmet
}).
exec
(
function
(
err
,
metainstructions
)
{
if
(
err
)
return
res
.
serverError
(
err
);
// Destroy method
MetaMethod
.
destroy
({
id
:
params
.
id_mmet
}).
exec
(
function
(
err
,
metamethod
)
{
if
(
err
||
!
metamethod
){
MetaInstruction
.
destroy
({
id_met
:
params
.
id
})
.
then
(
function
(
metainstructions
)
{
MetaMethod
.
destroy
({
id
:
params
.
id
})
.
then
(
function
(
metamethod
)
{
if
(
!
metamethod
){
sails
.
log
.
debug
(
"Destroy MetaMethod: "
+
err
);
return
res
.
serverError
(
"No meta method found"
);
}
return
res
.
ok
(
metamethod
);
})
.
catch
(
function
(
err
)
{
return
res
.
serverError
(
err
);
});
})
.
catch
(
function
(
err
)
{
return
res
.
serverError
(
err
);
});
}
...
...
sails/src/api/controllers/MethodController.js
View file @
59bc9458
sails/src/assets/app/i18n/en-gb.json
View file @
59bc9458
...
...
@@ -142,7 +142,9 @@
"minutes"
:
"minutes"
,
"month_totals"
:
"Month totals"
,
"name"
:
"Name"
,
"new_instruction"
:
"New instruction"
,
"new_method"
:
"New method"
,
"new_objective"
:
"New objective"
,
"new_session"
:
"New session"
,
"next_actions"
:
"Next actions"
,
"next_sessions"
:
"Next sessions"
,
...
...
@@ -169,7 +171,7 @@
"office_not_updated"
:
"Office not updated"
,
"office_updated"
:
"Office updated"
,
"offices"
:
"Offices"
,
"own_instructions"
:
"Own method
and instruction
s"
,
"own_instructions"
:
"Own method
template
s"
,
"own_labels"
:
"Your labels"
,
"own_pictos"
:
"Your pictograms"
,
"pages"
:
"Pages"
,
...
...
sails/src/assets/app/i18n/es-es.json
View file @
59bc9458
...
...
@@ -142,7 +142,9 @@
"minutes"
:
"minutos"
,
"month_totals"
:
"Totales mes"
,
"name"
:
"Nombre"
,
"new_instruction"
:
"Nueva instrucción"
,
"new_method"
:
"Nuevo método"
,
"new_objective"
:
"Nuevo objetivo"
,
"new_session"
:
"Nueva sesión"
,
"next_actions"
:
"Acciones posteriores"
,
"next_sessions"
:
"Sesiones posteriores"
,
...
...
@@ -169,7 +171,7 @@
"office_not_updated"
:
"El gabinete no se ha podido actualizar"
,
"office_updated"
:
"Gabinete actualizado"
,
"offices"
:
"Gabinetes"
,
"own_instructions"
:
"
Métodos e instruccione
s propias"
,
"own_instructions"
:
"
Plantillas de método
s propias"
,
"own_labels"
:
"Propias"
,
"own_pictos"
:
"Propios"
,
"pages"
:
"Páginas"
,
...
...
sails/src/assets/scripts/modules/student/controllers/instructions.js
View file @
59bc9458
...
...
@@ -22,7 +22,7 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
// Query to meta_methods to fill the select fill with precharged methods
// and supervisor template methods
$http
.
get
(
config
.
backend
+
'/met
amethods
/'
+
$scope
.
user
.
id
)
.
get
(
config
.
backend
+
'/met
hod/template
/'
+
$scope
.
user
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
// Add to list
$scope
.
methods_available
=
data
;
...
...
@@ -217,7 +217,6 @@ dashboardControllers.controller('StudentInstructionsCtrl', function StudentInstr
// Add instruction
$scope
.
add_instruction
=
function
(
method
){
$http
.
post
(
config
.
backend
+
'/instruction'
,
{
method
:
method
.
id
}
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
...
...
sails/src/assets/scripts/modules/supervisor/controllers/instructions.js
View file @
59bc9458
...
...
@@ -16,17 +16,14 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
//
$scope
.
methods_available
=
[];
// Query to meta_methods to fill the select fill with precharged methods
// and supervisor template methods
$http
.
get
(
config
.
backend
+
'/method/template
s
/owned/'
+
$scope
.
user
.
id
)
.
get
(
config
.
backend
+
'/method/template/owned/'
+
$scope
.
user
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
// Add to list
$scope
.
methods
=
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
:
$translate
.
instant
(
'new_method'
)
});
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
...
...
@@ -39,39 +36,35 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Add new method template (metamethod) selected to the student
$scope
.
add_method
=
function
(){
var
data
=
{
name
:
$translate
.
instant
(
"new_method"
);
var
new_data
=
{
name
:
$translate
.
instant
(
"new_method"
),
id_sup
:
$scope
.
user
.
id
};
$scope
.
method
.
unshift
(
data
);
$http
.
post
(
config
.
backend
+
'/method/template/save'
,
{
'id_sup'
:
$scope
.
user
.
id
})
.
then
(
//success
function
(
data
,
status
,
headers
,
config
)
{
ngToast
.
success
(
$translate
.
instant
(
'method_saved'
,
{
method_name
:
method
.
name
}));
}
,
function
(
data
,
status
,
headers
,
config
)
{
//error
ngToast
.
success
(
$translate
.
instant
(
'method_name_duplicated'
,
{
method_name
:
method
.
name
})),
}
);
.
post
(
config
.
backend
+
'/method/template'
,
new_data
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
data
.
metainstructions
=
[];
$scope
.
methods
.
unshift
(
data
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
//error
ngToast
.
warning
(
$translate
.
instant
(
"method_name_duplicated"
,
{
method_name
:
new_data
.
name
}));
});
};
// Delete method template
$scope
.
delete_method
=
function
(
method
){
newconfirm
(
$translate
.
instant
(
'confirmation'
)).
then
(
function
()
{
newconfirm
(
$translate
.
instant
(
'confirmation'
))
.
then
(
function
()
{
$http
.
delete
(
config
.
backend
+
'/method/template/'
+
$scope
.
method
.
id
)
.
delete
(
config
.
backend
+
'/method/template/'
+
method
.
id
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Delete Method Template and its Instructions'
);
ngToast
.
success
(
$translate
.
instant
(
'template_deleted'
));
ngToast
.
success
({
content
:
$translate
.
instant
(
'template_deleted'
)});
// Delete in select
for
(
var
i
=
0
;
i
<
$scope
.
methods
.
length
;
i
++
)
{
if
(
$scope
.
methods
[
i
].
id
==
$scope
.
method_selecte
d
.
id
){
if
(
$scope
.
methods
[
i
].
id
==
metho
d
.
id
){
$scope
.
methods
.
splice
(
i
,
1
);
$scope
.
method_selected
=
null
;
break
;
}
}
...
...
@@ -79,7 +72,7 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
});
}
});
};
// Update method template
...
...
@@ -88,7 +81,7 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Remove instructions as we only update title or description
var
method_to_save
=
{};
Object
.
assign
(
method_to_save
,
method
);
delete
method_to_save
.
instructions
;
delete
method_to_save
.
meta
instructions
;
$http
.
put
(
config
.
backend
+
'/method/template/'
+
method
.
id
,
method_to_save
)
...
...
@@ -103,12 +96,18 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Add instruction template
$scope
.
add_instruction
=
function
(
method
){
var
new_instruction
=
{
method
:
method
.
id
,
name
:
$translate
.
instant
(
"new_instruction"
),
objective
:
$translate
.
instant
(
"new_objective"
)
};
$http
.
post
(
config
.
backend
+
'/instruction/template/'
,
{
method
:
method
.
id
}
)
.
post
(
config
.
backend
+
'/instruction/template/'
,
new_instruction
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
'Added instruction:'
+
JSON
.
stringify
(
data
));
// Add in view
method
.
instructions
.
push
(
data
);
method
.
meta
instructions
.
push
(
data
);
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
console
.
log
(
"Error from API: "
+
data
.
error
);
...
...
@@ -137,11 +136,11 @@ dashboardControllers.controller('InstructionsCtrl', function InstructionsCtrl($s
// Buscar method
for
(
var
i
=
0
;
i
<
$scope
.
methods
.
length
;
i
++
)
{
var
m
=
$scope
.
methods
[
i
];
if
(
ins
.
method
==
m
.
id
){
if
(
ins
.
id_met
==
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
);
for
(
var
j
=
0
;
j
<
m
.
meta
instructions
.
length
;
j
++
)
{
if
(
ins
.
id
==
m
.
meta
instructions
[
j
].
id
){
$scope
.
methods
[
i
].
meta
instructions
.
splice
(
j
,
1
);
break
;
}
}
...
...
sails/src/assets/scripts/modules/supervisor/views/instructions.html
View file @
59bc9458
...
...
@@ -26,11 +26,9 @@
<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></th>
...
...
sails/src/config/routes.js
View file @
59bc9458
...
...
@@ -45,9 +45,9 @@ module.exports.routes = {
'POST /method/save'
:
'MethodController.save'
,
'DELETE /method/:id'
:
'MethodController.destroy'
,
'GET /method/template
s
/:id_sup'
:
'MetaMethodController.supVisible'
,
'GET /method/template
s
/owned/:id_sup'
:
'MetaMethodController.supOwned'
,
'POST /method/template
/new
'
:
'MetaMethodController.create'
,
'GET /method/template/:id_sup'
:
'MetaMethodController.supVisible'
,
'GET /method/template/owned/:id_sup'
:
'MetaMethodController.supOwned'
,
'POST /method/template'
:
'MetaMethodController.create'
,
'PUT /method/template/:id'
:
'MetaMethodController.update'
,
'DELETE /method/template/:id'
:
'MetaMethodController.destroy'
,
...
...
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