Skip to content

Commit

Permalink
feat(events): carga de recursos desde colección
Browse files Browse the repository at this point in the history
  • Loading branch information
juuliotero committed Jul 15, 2020
1 parent 4040e95 commit 17af03b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
25 changes: 25 additions & 0 deletions apps/backend/src/app/events/recursos/resource.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Resource } from './resource.schema';
import { MongoQuery, ResourceBase } from '@andes/core';
import { authenticate } from '../../application';
import * as mongoose from 'mongoose';
import { environment } from 'apps/backend/src/environments/environment';

class ResourceResource extends ResourceBase {
Model = Resource;
Expand All @@ -16,3 +18,26 @@ class ResourceResource extends ResourceBase {

export const ResourceCtr = new ResourceResource();
export const ResourcesRoutes = ResourceCtr.makeRoutes();

ResourcesRoutes.get('/resources/elements/:recurso', async (req, res, next) => {
const recurso = req.params.recurso;
let query = {};
if (req.query.search) {
query = { nombre: { $regex: req.query.search, $options: 'i' } }
}
const connectionMongoose = await mongoose.connect(environment.mongo_host, {
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 500
});
connectionMongoose.connection.db.collection(recurso, (err, collection) => {
if (err) {
return next(err);
}
collection.find(query, { projection: { nombre: 1 } }).toArray((err, data) => {
if (err) {
return next(err);
}
return res.json(data);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { OcurrenceEvent, OcurrenceEventsService } from '../../services/ocurrence
import { Plex } from '@andes/plex';
import { Location } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { SelectSearchService } from '../../../shared/select-search.service';

@Component({
selector: 'occurrence-events-crud',
Expand All @@ -31,7 +30,7 @@ export class OccurrenceEventsCrudComponent implements OnInit {
private plex: Plex,
private location: Location,
private route: ActivatedRoute
) {}
) { }

ngOnInit() {
this.institutionService.search({}).subscribe(rta => {
Expand All @@ -57,7 +56,7 @@ export class OccurrenceEventsCrudComponent implements OnInit {
for (const key in this.indicadores) {
if (key.startsWith('id_')) {
this.indicadores[key.substring(3)] = {
id: this.indicadores[key],
_id: this.indicadores[key],
nombre: this.indicadores[key.substring(3)]
};
}
Expand Down Expand Up @@ -93,7 +92,7 @@ export class OccurrenceEventsCrudComponent implements OnInit {
for (const key in this.indicadores) {
const indicador = this.eventSelected.indicadores.find(indicador => indicador.key === key);
if (indicador && indicador.type === 'select') {
indicadores[`id_${key}`] = this.indicadores[key].id;
indicadores[`id_${key}`] = this.indicadores[key]._id;
indicadores[key] = this.indicadores[key].nombre;
} else {
indicadores[key] = this.indicadores[key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class SelectSearchDirective implements OnDestroy, AfterContentInit {
private _viewContainerRef: ViewContainerRef
) {
const plexSelect: PlexSelectComponent = this._viewContainerRef['_data'].componentView.component;
plexSelect.idField = 'id';
plexSelect.idField = '_id';
plexSelect.labelField = 'nombre';
}

Expand Down Expand Up @@ -62,4 +62,4 @@ export class SelectSearchDirective implements OnDestroy, AfterContentInit {
this.subscription.unsubscribe();
}
}
}
}
7 changes: 3 additions & 4 deletions apps/frontend/src/app/shared/select-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ export class SelectSearchService {
get(recurso, texto): Observable<any[]> {
let search = null;
if (texto) {
search = `^${texto}`;
search = texto;
}
const params = {
search,
fields: 'nombre'
search
}
return this.server.get(`/${recurso}`, { params, showError: true });
return this.server.get(`/resources/elements/${recurso}`, { params, showError: true });
}

}

0 comments on commit 17af03b

Please sign in to comment.