Add extension for map sort by value
This commit is contained in:
parent
430a64f592
commit
6ba7d9ffb0
|
@ -14,7 +14,7 @@
|
||||||
<div id="timelines">
|
<div id="timelines">
|
||||||
<div v-for="(value, key, index) in pubTL" :key="index" class="tl">
|
<div v-for="(value, key, index) in pubTL" :key="index" class="tl">
|
||||||
{{value.name}}
|
{{value.name}}
|
||||||
<div v-for="[id,status] in Array.from(value.statuses)" :key="id" class="tl">{{status.id}}</div>
|
<div v-for="[id,status] in sortedStatus(value.statuses)" :key="id" class="tl">{{status.id}}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<BaseButton
|
<BaseButton
|
||||||
|
@ -31,6 +31,8 @@ import { ipcRenderer } from 'electron'
|
||||||
import { Component, Vue } from 'vue-property-decorator'
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import { Status } from 'megalodon'
|
import { Status } from 'megalodon'
|
||||||
|
|
||||||
|
import '@/extensions/map-sortbyvalue' // Add sortByValue function to Map prototype
|
||||||
|
|
||||||
type DeleteListener = (e: Event, id: number) => void
|
type DeleteListener = (e: Event, id: number) => void
|
||||||
type Instance = string
|
type Instance = string
|
||||||
type Timeline = {
|
type Timeline = {
|
||||||
|
@ -61,6 +63,12 @@ export default class AddColumn extends Vue {
|
||||||
return this.instance != ''
|
return this.instance != ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sortedStatus(statuses: Map<number, Status>): Map<number, Status> {
|
||||||
|
return statuses.sortByValue((s1, s2): number => {
|
||||||
|
return s1.created_at > s2.created_at ? -1 : 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public addTL() {
|
public addTL() {
|
||||||
let timeline: Timeline = { name: this.instance }
|
let timeline: Timeline = { name: this.instance }
|
||||||
|
|
||||||
|
|
9
src/extensions/map-sortbyvalue.ts
Normal file
9
src/extensions/map-sortbyvalue.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
interface Map<K, V> {
|
||||||
|
sortByValue(f: (value1: V, value2: V) => number): Map<K, V>
|
||||||
|
}
|
||||||
|
Map.prototype.sortByValue = function (f: (value1: any, value2: any) => number): Map<any, any> {
|
||||||
|
return new Map([...(this as Map<any, any>)].sort((keyValue1, keyValue2) => {
|
||||||
|
return f(keyValue1[1], keyValue2[1]);
|
||||||
|
}))
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user