Add extension for map sort by value

This commit is contained in:
kPherox 2019-04-24 19:47:26 +09:00
parent 430a64f592
commit 6ba7d9ffb0
No known key found for this signature in database
GPG Key ID: C04751C2BFA2F62D
2 changed files with 18 additions and 1 deletions

View File

@ -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 }

View 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]);
}))
}