FiltersPackage.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import Modularity from 'modularity-front';
  3. import { Row, Col } from 'react-materialize';
  4. import Button from '@material-ui/core/Button';
  5. import Form from '../Modules/Form.js';
  6. import Repository from '../Services/Repository.js';
  7. import FilterModule from '../Modules/FilterModule';
  8. import './FiltersPackage.css';
  9. let Module = Modularity.Module;
  10. class FiltersPackage extends Modularity.Module {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. model: []
  15. }
  16. let propertiesService = {
  17. Token: (t) => {
  18. this.Token.set(t);
  19. this.forceUpdate();
  20. }
  21. }
  22. this.Table.onUpdate(() => this.updateRepo())
  23. if(this.Table.value)this.updateRepo()
  24. }
  25. updateRepo() {
  26. this.productsRepo = new Repository(this.Table.value);
  27. this.Repository.set(this.productsRepo);
  28. this.productsRepo.model()
  29. .then((model) => {
  30. let res = [];
  31. for(var key in model) {
  32. model[key].Filter && res.push(model[key].Filter);
  33. }
  34. return res;
  35. })
  36. .then((model) => this.setState({model}));
  37. }
  38. setFilters(f) {
  39. if(!f)return;
  40. this.productsRepo.setFilters(f);
  41. this.Repository.set(this.productsRepo);
  42. }
  43. render() {
  44. return <div>
  45. Filter
  46. <FilterModule Inputs={this.state.model} Filters={(f) => this.setFilters(f)}/>
  47. {super.render()}
  48. </div>;
  49. }
  50. }
  51. FiltersPackage.Inputs = {
  52. Table: {
  53. type: Modularity.Module.Types.Text
  54. }
  55. }
  56. FiltersPackage.Outputs = {
  57. Token: {},
  58. Repository: {}
  59. }
  60. FiltersPackage.Category = "NikatlasPackages";
  61. FiltersPackage.EditPosition = "top-center";
  62. export default FiltersPackage;