Skip to content

Commit

Permalink
feat: add filter for stable branch & github pr
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Mar 20, 2024
1 parent e35b0c6 commit 38fa750
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
46 changes: 42 additions & 4 deletions frontend/src/pages/pipelines/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
<template>
<v-container>
<v-row>
<v-col>
<v-expansion-panels>
<v-expansion-panel title="Pipelines">
<v-expansion-panel-text>
<v-container class="pa-0">
<v-row class="pa-0">
<v-col class="pa-0">
<v-checkbox
v-model="stableOnly"
label="Stable Branch Only"
@update:model-value="loadItems"
:hide-details="true">
</v-checkbox>
</v-col>
<v-col class="pa-0">
<v-checkbox
v-model="githubPROnly"
label="GitHub PR Only"
@update:model-value="loadItems"
:hide-details="true">
</v-checkbox>
</v-col>
<v-spacer></v-spacer>
<v-col class="d-flex align-end justify-end">
<v-btn @click="loadItems">Refresh</v-btn>
</v-col>
</v-row>
</v-container>
</v-expansion-panel-text>
</v-expansion-panel>
</v-expansion-panels>
</v-col>
</v-row>
<v-row>
<v-col>
<v-data-table-server
:items-per-page="itemsPerPage"
v-model:items-per-page="itemsPerPage"
v-model:page="page"
:headers="headers"
:items="serverItems"
:items-length="totalItems"
Expand Down Expand Up @@ -184,6 +219,7 @@
export default {
data: () => ({
page: 1,
itemsPerPage: 25,
headers: [
{ title: 'Status', key: 'status', sortable: false },
Expand All @@ -193,12 +229,14 @@
],
loading: true,
totalItems: 0,
serverItems: []
serverItems: [],
stableOnly: false,
githubPROnly: false,
}),
methods: {
async loadItems (opts: LoadItemsOpts) {
async loadItems () {
this.loading = true;
let data = (await axios.get(hostname + `/api/pipeline/list?page=${opts.page}&items_per_page=${opts.itemsPerPage}`)).data;
let data = (await axios.get(hostname + `/api/pipeline/list?page=${this.page}&items_per_page=${this.itemsPerPage}&stable_only=${this.stableOnly}&github_pr_only=${this.githubPROnly}`)).data;
this.totalItems = data.total_items;
this.serverItems = data.items;
this.loading = false;
Expand Down
14 changes: 12 additions & 2 deletions server/src/routes/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ pub async fn pipeline_info(
pub struct PipelineListRequest {
page: i64,
items_per_page: i64,
stable_only: bool,
github_pr_only: bool,
}

#[derive(Serialize)]
Expand Down Expand Up @@ -177,9 +179,17 @@ pub async fn pipeline_list(
.count()
.get_result(conn)?;

let sql = crate::schema::pipelines::dsl::pipelines
let mut sql = crate::schema::pipelines::dsl::pipelines
.left_join(crate::schema::users::dsl::users)
.order_by(crate::schema::pipelines::dsl::id.desc());
.order_by(crate::schema::pipelines::dsl::id.desc())
.into_boxed();

if query.stable_only {
sql = sql.filter(crate::schema::pipelines::dsl::git_branch.eq("stable"));
}
if query.github_pr_only {
sql = sql.filter(crate::schema::pipelines::dsl::github_pr.is_not_null());
}

let res: Vec<(Pipeline, Option<User>)> = if query.items_per_page == -1 {
sql.load::<(Pipeline, Option<User>)>(conn)?
Expand Down

0 comments on commit 38fa750

Please sign in to comment.