iss32-editar-postulantes-cargo, se agrego la edición de tags

parent f7ebe278
<div class="row">
<h2 class="sub-header">Cargos</h2>
<button class="btn btn-default" ng-click="vm.crear()">Crear Cargo</button>
<div class="table-responsive">
<table class="table table-striped">
<thead>
......
tags-input .tags .tag-item {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
display: inline-block;
white-space: nowrap;
margin: -1px 5px 5px 0;
height: 22px;
vertical-align: top;
cursor: default;
color: #767676;
background-color: #fff;
border-color: #ccc;
}
......@@ -2,7 +2,7 @@
(()=> {
class PostulanteController {
constructor($stateParams, postulanteService, datoPostulanteService,tipoDatoService, Modal) {
constructor($stateParams, postulanteService, datoPostulanteService,tipoDatoService, Modal, tagService, tagPostulanteService) {
this.errores = {}; // lista de errores
this.postulanteEnviado = false; // se refiere a si se intento enviar el formulario del postulante
this.tagsEnviado = false;
......@@ -11,9 +11,10 @@
this.service = postulanteService;
this.datoPostulanteService = datoPostulanteService;
this.tipoDatoService = tipoDatoService;
this.tagService = tagService;
this.tagPostulanteService = tagPostulanteService;
this.id = $stateParams.postulanteId;
this.service.getPostulante(this.id).then(postulante=> {
console.log(postulante);
this.postulante = postulante;
this.tags = [];
this.postulante.Tags.forEach(tag=> {
......@@ -57,6 +58,70 @@
});
}
}
guardarTags(form){
this.enviado = true;
var thisRaiz = this;
if(form.$valid){
var tagsObjeto = [];
var tagsPostulante = [];
var tagsEnvio = [];
var tagsDiferencia = [];
//Tags total de la base de datosEnviado
this.tagService.getTags(1, 1000)
.then(tag=>{
tag.rows.forEach(t=> {
tagsObjeto.push(t);
});
});
//Tags enviados con fomulario
this.tags.forEach(tag=> {
tagsEnvio.push(tag.text);
});
this.service.getPostulante(this.id)
.then(function(tagActual){
//Armando tags de Base de Datos
tagActual.Tags.forEach(registroTag => {
tagsPostulante.push(registroTag.nombre);
});
tagsDiferencia = (tagsEnvio.filter(x => tagsPostulante.indexOf(x) == -1)).concat(tagsPostulante.filter(x => tagsEnvio.indexOf(x) == -1));
tagsEnvio.forEach(tag=>{
var nuevoTagPostulante = {};
if( (tagsDiferencia.indexOf(tag)) != -1 ){ //caso de estar en tagsDiferencia
var tagObj = tagsObjeto.filter(function(obj){return obj.nombre === tag;})[0];
if(tagObj){
nuevoTagPostulante.fk_postulante = thisRaiz.id;
nuevoTagPostulante.fk_tag = tagObj._id;
thisRaiz.tagPostulanteService.crearTagPostulante(nuevoTagPostulante);
}else{
var nuevoTag = {};
nuevoTag.nombre = tag;
thisRaiz.tagService.crearTag(nuevoTag)
.then(creadoTag=>{
nuevoTagPostulante.fk_postulante = thisRaiz.id;
nuevoTagPostulante.fk_tag = creadoTag._id;
tagsObjeto.push(creadoTag);
thisRaiz.tagPostulanteService.crearTagPostulante(nuevoTagPostulante);
});
}
}
})
tagActual.Tags.forEach(tag=>{
if( (tagsEnvio.indexOf(tag.nombre)) == -1 ){
thisRaiz.tagPostulanteService.eliminarTagPostulante(tag.TagPostulante._id)
//console.log(tag.TagPostulante._id);
}
});
});
form.tags.$dirty = false;
}
}
}
angular.module('moduloPersonalApp')
.controller('PostulantesEditarCtrl', PostulanteController);
......
......@@ -92,14 +92,14 @@
</uib-accordion-group>
<uib-accordion-group heading="Tags" class="panel-primary" is-open="true">
<div class="col-md-10">
<form class="form" name="form" ng-submit="vm.editar(form)" novalidate>
<tags-input ng-model="vm.tags">
<form class="form" name="formTags" ng-submit="vm.guardarTags(formTags)" novalidate>
<tags-input ng-model="vm.tags" name="tags" placeholder="Adicionar Tags">
<!--<auto-complete source="vm.loadTags($query)"></auto-complete>-->
</tags-input>
<br>
<div class="pull-right">
<button class="btn btn-primary" type="submit">
Guardar
<div class="pull-right" >
<button class="btn btn-primary" name="submitTag" type="submit" ng-hide="!formTags.tags.$dirty">
Guardar Tag
</button>
</div>
</form>
......
......@@ -23,6 +23,12 @@
<input type="text" name="ci" class="form-control" ng-model="vm.postulante.ci" required>
</div>
<tag-manager tags="tags" autocomplete="allTags"></tag-manager>
<hr>
<h3>Current Tags</h3>
<ul class="list-unstyled">
<li ng-repeat="tag in tags">{{tag}}</li>
</ul>
<div class="form-group has-error">
......@@ -41,3 +47,5 @@
</div>
<hr>
</div>
......@@ -16,6 +16,10 @@
getTag(id) {
return this.resource.get({id: id});
}
crearTag(tag) {
return this.resource.save(tag).$promise;
}
}
angular.module('moduloPersonalApp')
......
......@@ -18,13 +18,19 @@
incluye: ['Postulante', 'Tag']
}).$promise;
}
gettagPostulante(id) {
return this.resource.get({id: id});
}
crearTagPostulante(tag) {
return this.resource.save(tag).$promise;
}
eliminarTagPostulante(id) {
return this.resource.remove({id: id}).$promise;
}
}
angular.module('moduloPersonalApp')
.service('tagPostulanteService', TagPostulanteService);
})();
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