Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue 3 migration #109

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fetching namespaces
  • Loading branch information
amimof committed Jun 12, 2024
commit 792c771b23b82286a54ead4a295e113a8e2299dc
9 changes: 6 additions & 3 deletions web2/src/components/Loader.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<script>
<script setup>
</script>

<template>
<div class="d-flex justify-content-center">
Loading ...
<div class="spinner-border" style="color: rgb(0, 123, 255)" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</template>

<style lang="scss" scoped>
<style scoped>
</style>



15 changes: 10 additions & 5 deletions web2/src/components/Namespaces.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const activeNamespace = ref(0)
const searchString = ref('')
const searchfield = ref(null);

onMounted(() => {
store.getNamespaces()
onMounted(async () => {
reload();
window.addEventListener("keydown", handlePress);
})

Expand Down Expand Up @@ -97,6 +97,10 @@ function sort() {
}
}

function reload() {
store.getNamespaces();
}

</script>

<template>
Expand All @@ -112,16 +116,17 @@ function sort() {
<font-awesome-icon :icon="['fas', 'arrow-up-wide-short']" class="icon" v-if="isSortDown" />
<font-awesome-icon :icon="['fas', 'arrow-down-wide-short']" class="icon" v-if="!isSortDown" />
</button>
<button type="button" class="btn btn-outline-secondary" :disabled="store.isNamespacesLoading" @click="reload()"><font-awesome-icon :icon="['fas', 'redo']" /></button>
</div>

<Loader v-if="isLoading" />
<Loader v-if="store.isNamespacesLoading" />

<h5 v-if="store.namespaces.length == 0 && !isLoading && !isError">No namespaces found</h5>

<div class="row" v-if="isLoading && !isError">
<div class="row" v-if="!store.isNamespacesLoading && !isError">
<div class="col" v-if="store.namespaces.length > 0">
<h6 v-if="store.recentNamespaces.length > 0">All</h6>
<NamespacesList :items="store.namespaces" :active="activeNamespace"/>
<NamespacesList :items="store.filteredNamespaces" :active="activeNamespace"/>
</div>
<div class="col-4" v-if="store.recentNamespaces.length > 0">
<h6>Recent</h6>
Expand Down
13 changes: 3 additions & 10 deletions web2/src/components/NamespacesList.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
<script setup>
import { ref, onMounted, defineProps } from 'vue';
import { defineProps } from 'vue';
import PodCount from './PodCount.vue'
import { useNamespacesStore } from '@/stores/namespace';

const store = useNamespacesStore();
// const active = ref(0);
const props = defineProps(['active']);

onMounted(() => {
store.getNamespaces();
});
const props = defineProps(['active', 'items']);

function getActive(index) {
if(props.active == index) {
Expand All @@ -23,7 +16,7 @@ function getActive(index) {
<template>
<div class="h-100">
<ul class="list-group">
<li :class="'list-group-item ' + getActive(index)" :aria-current="active == index" v-for="(item, index) in store.filteredNamespaces">
<li :class="'list-group-item ' + getActive(index)" :aria-current="active == index" v-for="(item, index) in items">
<div class="d-flex justify-content-between align-items-center">
<span class="mb-1">{{ item.metadata.name }}</span>
<small><span class="namespace-icons"><i class="far fa-clock"></i> {{ $filters.timeAgo(item.metadata.creationTimestamp) }}</span> <span class="namespace-icons"><PodCount :namespace="item.metadata.name"/></span></small>
Expand Down
1 change: 0 additions & 1 deletion web2/src/components/PodCount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const apiUrl = "http://127.0.0.1:8080/api";
const controller = new AbortController();
const signal = controller.signal;

const pods = ref([]);
const isLoaded = ref(true);
const podCount = ref(0);

Expand Down
13 changes: 13 additions & 0 deletions web2/src/services/namespaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const apiUrl = "http://127.0.0.1:8080/api";

async function getNamespace(namespace) {
return await fetch(`${apiUrl}/namespaces/${namespace}`);
}

async function getNamespaces() {
return await fetch(`${apiUrl}/namespaces`);
}
export default {
getNamespace,
getNamespaces,
};
36 changes: 29 additions & 7 deletions web2/src/stores/namespace.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
import { ref, computed } from "vue";
import { defineStore } from "pinia";
import axios from "axios";
import utils from "../common/utils";

const apiUrl = "http://127.0.0.1:8080/api";
import NamespaceService from "../services/namespaces";

export const useNamespacesStore = defineStore("namespaces", () => {
const namespaces = ref([]);
const filteredNamespaces = ref([]);
const recentNamespaces = ref([]);
const nsSearchString = ref("");
const nsSort = ref("asc");
const isNamespacesLoading = ref(false);

async function getNamespaces() {
return axios.get(`${apiUrl}/namespaces`).then((res) => {
namespaces.value = res.data.items;
filteredNamespaces.value = res.data.items;
});
isNamespacesLoading.value = true;
namespaces.value = [];
filteredNamespaces.value = [];

try {
const response = await NamespaceService.getNamespaces();
if (!response.ok) {
throw new Error(
`unable to fetch namespaces with status ${response.status}`
);
}
const data = await response.json();
namespaces.value = data.items;
filteredNamespaces.value = data.items;
isNamespacesLoading.value = false;
return {
data: data.items,
error: null,
};
} catch (error) {
isNamespacesLoading.value = false;
return {
data: null,
error: error,
};
}
}

function filterNamespaces(searchString) {
Expand All @@ -40,5 +61,6 @@ export const useNamespacesStore = defineStore("namespaces", () => {
filterNamespaces,
filteredNamespaces,
sortNamespaces,
isNamespacesLoading,
};
});