Advertisement
AndersonARC

Untitled

Apr 21st, 2020
1,773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data: function() {
  2.     const groups: Group[] = []
  3.     const selectedGroups: number[] = []
  4.     return {
  5.         plots: Utilities.instance.plots,
  6.         groups: groups,
  7.         plotSet: new Set<PlotProvider>(), //todo delete it
  8.         groupSet: new Set<number>(),
  9.         selectedPlots: Utilities.instance.getSelected(),
  10.         selectedPlotsName: "",
  11.         selectedGroups: selectedGroups,
  12.         selectedGroupsName: ""
  13.     }
  14.   },
  15.   methods: {
  16.         setPlot(type: string, field: string, fieldValue: string, oldSelected: Plots): void {
  17.             const selected = this.selectedPlots[type]
  18.             const plots = this.plots[type]
  19.             console.log("set")
  20.             console.log(this.groupSet)
  21.             this.groupSet.forEach(group_id => {
  22.                 console.log("PROCESSING " + type + " " + field + " " + fieldValue + " " + group_id)
  23.                 const otherField = (
  24.                     field === "page" ?
  25.                     "kind" : "page"
  26.                 )
  27.                 let add = false
  28.                     this.plotSet.forEach(value => {
  29.                         add = !(value.type === type && value[field] === fieldValue && value[otherField] === otherFieldValue && value.group_id === group_id)
  30.                     })// add stays here
  31.                 for (const otherFieldValue of selected[otherField]) {
  32.                     console.log("FOR " + type + " " + field + " " + fieldValue + " " + group_id + " " + otherField + " " + otherFieldValue)
  33.                     const provider = (
  34.                         otherField === "page" ?
  35.                         new PlotProvider(Number(group_id), type, otherFieldValue, fieldValue)
  36.                         :
  37.                         new PlotProvider(Number(group_id), type, fieldValue, otherFieldValue)
  38.                     )
  39.                     //todo refactor
  40.                    
  41.                     if (selected[otherField].length === 0 && add && plots[otherField].length === 1) {
  42.                         selected[otherField].push(plots[otherField][0])
  43.                     }
  44.                     if (add) {
  45.                         this.plotSet.add(provider)
  46.                     } else {
  47.                         this.plotSet.delete(provider)
  48.                     }
  49.                 }
  50.                 if (selected[field].length === 0 && plots[field].length === 1) {
  51.                     selected[otherField] = []
  52.                 }
  53.             })
  54.         },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement