mirror of
				https://github.com/Fabio286/antares.git
				synced 2025-06-05 21:59:22 +02:00 
			
		
		
		
	feat: improved data table sorts
This commit is contained in:
		| @@ -14,14 +14,18 @@ export default (connections) => { | |||||||
|       } |       } | ||||||
|    }); |    }); | ||||||
|  |  | ||||||
|    ipcMain.handle('get-table-data', async (event, { uid, schema, table }) => { |    ipcMain.handle('get-table-data', async (event, { uid, schema, table, sortParams }) => { | ||||||
|       try { |       try { | ||||||
|          const result = await connections[uid] |          const query = connections[uid] | ||||||
|             .select('*') |             .select('*') | ||||||
|             .schema(schema) |             .schema(schema) | ||||||
|             .from(table) |             .from(table) | ||||||
|             .limit(1000) |             .limit(1000); | ||||||
|             .run({ details: true }); |  | ||||||
|  |          if (sortParams && sortParams.field && sortParams.dir) | ||||||
|  |             query.orderBy({ [sortParams.field]: sortParams.dir.toUpperCase() }); | ||||||
|  |  | ||||||
|  |          const result = await query.run({ details: true }); | ||||||
|  |  | ||||||
|          return { status: 'success', response: result }; |          return { status: 'success', response: result }; | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -99,6 +99,7 @@ export default { | |||||||
|          if (!query || this.isQuering) return; |          if (!query || this.isQuering) return; | ||||||
|          this.isQuering = true; |          this.isQuering = true; | ||||||
|          this.clearTabData(); |          this.clearTabData(); | ||||||
|  |          this.$refs.queryTable.resetSort(); | ||||||
|  |  | ||||||
|          try { // Query Data |          try { // Query Data | ||||||
|             const params = { |             const params = { | ||||||
|   | |||||||
| @@ -123,8 +123,11 @@ export default { | |||||||
|       primaryField () { |       primaryField () { | ||||||
|          return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false; |          return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false; | ||||||
|       }, |       }, | ||||||
|  |       isHardSort () { | ||||||
|  |          return this.mode === 'table' && this.localResults.length === 1000; | ||||||
|  |       }, | ||||||
|       sortedResults () { |       sortedResults () { | ||||||
|          if (this.currentSort) { |          if (this.currentSort && !this.isHardSort) { | ||||||
|             return [...this.localResults].sort((a, b) => { |             return [...this.localResults].sort((a, b) => { | ||||||
|                let modifier = 1; |                let modifier = 1; | ||||||
|                const valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort]; |                const valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort]; | ||||||
| @@ -228,7 +231,7 @@ export default { | |||||||
|          return row[primaryFieldName]; |          return row[primaryFieldName]; | ||||||
|       }, |       }, | ||||||
|       setLocalResults () { |       setLocalResults () { | ||||||
|          this.resetSort(); |          // this.resetSort(); | ||||||
|          this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows |          this.localResults = this.resultsWithRows[this.resultsetIndex] && this.resultsWithRows[this.resultsetIndex].rows | ||||||
|             ? this.resultsWithRows[this.resultsetIndex].rows.map(item => { |             ? this.resultsWithRows[this.resultsetIndex].rows.map(item => { | ||||||
|                return { ...item, _id: uidGen() }; |                return { ...item, _id: uidGen() }; | ||||||
| @@ -342,6 +345,9 @@ export default { | |||||||
|             this.currentSortDir = 'asc'; |             this.currentSortDir = 'asc'; | ||||||
|             this.currentSort = field; |             this.currentSort = field; | ||||||
|          } |          } | ||||||
|  |  | ||||||
|  |          if (this.isHardSort) | ||||||
|  |             this.$emit('hard-sort', { field: this.currentSort, dir: this.currentSortDir }); | ||||||
|       }, |       }, | ||||||
|       resetSort () { |       resetSort () { | ||||||
|          this.currentSort = ''; |          this.currentSort = ''; | ||||||
|   | |||||||
| @@ -63,6 +63,7 @@ | |||||||
|             mode="table" |             mode="table" | ||||||
|             @update-field="updateField" |             @update-field="updateField" | ||||||
|             @delete-selected="deleteSelected" |             @delete-selected="deleteSelected" | ||||||
|  |             @hard-sort="hardSort" | ||||||
|          /> |          /> | ||||||
|       </div> |       </div> | ||||||
|       <ModalNewTableRow |       <ModalNewTableRow | ||||||
| @@ -135,6 +136,7 @@ export default { | |||||||
|          if (this.isSelected) { |          if (this.isSelected) { | ||||||
|             this.getTableData(); |             this.getTableData(); | ||||||
|             this.lastTable = this.table; |             this.lastTable = this.table; | ||||||
|  |             this.$refs.queryTable.resetSort(); | ||||||
|          } |          } | ||||||
|       }, |       }, | ||||||
|       isSelected (val) { |       isSelected (val) { | ||||||
| @@ -156,7 +158,7 @@ export default { | |||||||
|       ...mapActions({ |       ...mapActions({ | ||||||
|          addNotification: 'notifications/addNotification' |          addNotification: 'notifications/addNotification' | ||||||
|       }), |       }), | ||||||
|       async getTableData () { |       async getTableData (sortParams) { | ||||||
|          if (!this.table) return; |          if (!this.table) return; | ||||||
|          this.isQuering = true; |          this.isQuering = true; | ||||||
|  |  | ||||||
| @@ -167,7 +169,8 @@ export default { | |||||||
|          const params = { |          const params = { | ||||||
|             uid: this.connection.uid, |             uid: this.connection.uid, | ||||||
|             schema: this.schema, |             schema: this.schema, | ||||||
|             table: this.workspace.breadcrumbs.table |             table: this.workspace.breadcrumbs.table, | ||||||
|  |             sortParams | ||||||
|          }; |          }; | ||||||
|  |  | ||||||
|          try { // Table data |          try { // Table data | ||||||
| @@ -190,6 +193,9 @@ export default { | |||||||
|       reloadTable () { |       reloadTable () { | ||||||
|          this.getTableData(); |          this.getTableData(); | ||||||
|       }, |       }, | ||||||
|  |       hardSort (sortParams) { | ||||||
|  |          this.getTableData(sortParams); | ||||||
|  |       }, | ||||||
|       showAddModal () { |       showAddModal () { | ||||||
|          this.isAddModal = true; |          this.isAddModal = true; | ||||||
|       }, |       }, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user