Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf330ebb

Browse files
gitstart_botjschwartzentruber
gitstart_bot
authored andcommitted
Migrate Pools component to Vue3
1 parentc091b3e commitf330ebb

File tree

2 files changed

+205
-145
lines changed

2 files changed

+205
-145
lines changed

‎server/frontend/src/components/Pools/List.vue‎

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,47 @@
77
<thead>
88
<tr>
99
<th
10-
v-on:click.exact="sortBy('pool_id')"
11-
v-on:click.ctrl.exact="addSort('pool_id')"
1210
:class="{
1311
active:
1412
sortKeys.includes('pool_id') || sortKeys.includes('-pool_id'),
1513
}"
1614
width="25px"
15+
@click.exact="sortBy('pool_id')"
16+
@click.ctrl.exact="addSort('pool_id')"
1717
>
1818
ID
1919
</th>
2020
<th
21-
v-on:click.exact="sortBy('pool_name_isort')"
22-
v-on:click.ctrl.exact="addSort('pool_name_isort')"
2321
:class="{
2422
active:
2523
sortKeys.includes('pool_name_isort') ||
2624
sortKeys.includes('-pool_name_isort'),
2725
}"
2826
width="100px"
27+
@click.exact="sortBy('pool_name_isort')"
28+
@click.ctrl.exact="addSort('pool_name_isort')"
2929
>
3030
Name
3131
</th>
3232
<th
33-
v-on:click.exact="sortBy('running')"
34-
v-on:click.ctrl.exact="addSort('running')"
3533
:class="{
3634
active:
3735
sortKeys.includes('running') || sortKeys.includes('-running'),
3836
}"
3937
width="75px"
38+
@click.exact="sortBy('running')"
39+
@click.ctrl.exact="addSort('running')"
4040
>
4141
# of Tasks (Running/Requested)
4242
</th>
4343
<th
44-
v-on:click.exact="sortBy('status')"
45-
v-on:click.ctrl.exact="addSort('status')"
4644
:class="{
4745
active:
4846
sortKeys.includes('status') || sortKeys.includes('-status'),
4947
}"
5048
width="150px"
49+
@click.exact="sortBy('status')"
50+
@click.ctrl.exact="addSort('status')"
5151
>
5252
Status
5353
</th>
@@ -81,42 +81,32 @@
8181
<script>
8282
import_throttlefrom"lodash/throttle";
8383
importswalfrom"sweetalert";
84-
import {E_SERVER_ERROR,multiSort}from"../../helpers";
84+
import {computed,defineComponent,ref}from"vue";
8585
import*asapifrom"../../api";
86+
import {E_SERVER_ERROR,multiSort }from"../../helpers";
8687
87-
exportdefault {
88+
exportdefaultdefineComponent({
89+
name:"PoolsList",
8890
mixins: [multiSort],
89-
data:function() {
91+
setup() {
9092
constdefaultSortKeys= ["pool_name_isort"];
9193
constvalidSortKeys= ["pool_id","pool_name_isort","running","status"];
92-
return {
93-
defaultSortKeys: defaultSortKeys,
94-
loading:true,
95-
pools:null,
96-
sortKeys: [...defaultSortKeys],
97-
validSortKeys: validSortKeys,
98-
};
99-
},
100-
created:function () {
101-
this.fetch();
102-
},
103-
computed: {
104-
orderedPools:function () {
105-
returnthis.sortData(this.pools);
106-
},
107-
},
108-
methods: {
109-
buildParams() {
94+
constloading=ref(true);
95+
constpools=ref(null);
96+
constsortKeys=ref([...defaultSortKeys]);
97+
98+
constbuildParams= ()=> {
11099
return {
111100
vue:"1",
112101
};
113-
},
114-
fetch:_throttle(
115-
asyncfunction () {
116-
this.loading=true;
102+
};
103+
104+
constfetch=_throttle(
105+
async ()=> {
106+
loading.value=true;
117107
try {
118-
constdata=awaitapi.listPools(this.buildParams());
119-
this.pools=data.map((pool)=> {
108+
constdata=awaitapi.listPools(buildParams());
109+
pools.value=data.map((pool)=> {
120110
pool.pool_name_isort=pool.pool_name.toLowerCase();
121111
return pool;
122112
});
@@ -126,17 +116,61 @@ export default {
126116
err.response.status===400&&
127117
err.response.data
128118
) {
129-
// eslint-disable-next-line no-console
130119
console.debug(err.response.data);
131120
swal("Oops",E_SERVER_ERROR,"error");
132-
this.loading=false;
121+
loading.value=false;
133122
}
134123
}
135-
this.loading=false;
124+
loading.value=false;
136125
},
137126
500,
138127
{ trailing:true },
139-
),
128+
);
129+
130+
constsortBy= (key)=> {
131+
sortKeys.value= [key.startsWith("-")?key.slice(1):`-${key}`];
132+
};
133+
134+
constaddSort= (key)=> {
135+
consti=sortKeys.value.indexOf(key);
136+
constni=sortKeys.value.indexOf(`-${key}`);
137+
if (i<0&& ni<0) {
138+
sortKeys.value.push(key);
139+
}elseif (i>=0) {
140+
sortKeys.value[i]=`-${key}`;
141+
}elseif (ni>=0) {
142+
sortKeys.value.splice(ni,1);
143+
}
144+
};
145+
146+
constsortData= (data)=> {
147+
if (!data)return [];
148+
constkeys=sortKeys.value;
149+
return [...data].sort((a,b)=> {
150+
for (constkeyof keys) {
151+
constdesc=key.startsWith("-");
152+
constk= desc?key.slice(1): key;
153+
if (a[k]> b[k])return desc?-1:1;
154+
if (a[k]< b[k])return desc?1:-1;
155+
}
156+
return0;
157+
});
158+
};
159+
160+
constorderedPools=computed(()=>sortData(pools.value));
161+
162+
fetch();
163+
164+
return {
165+
loading,
166+
pools,
167+
sortKeys,
168+
orderedPools,
169+
sortBy,
170+
addSort,
171+
validSortKeys,
172+
defaultSortKeys,
173+
};
140174
},
141-
};
175+
});
142176
</script>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp