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

Defect 12 most recent version default option #50

Merged
merged 4 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ on: [pull_request]

jobs:
main:
runs-on: self-hosted
container: node:16
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['16.x']
permissions: write-all
steps:
- name: Checkout code
Expand Down
506 changes: 287 additions & 219 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/api/dlt/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export default class DltApi extends DltInterface {
return data;
}

async getMostRecentVersion(pack: Package) {
const { data } = await axios.post(this.#getLink('get-most-recent-version'), pack);
console.log(data);
return data;
}

async getMetrics() {
const { data } = await axios.get(this.#getLink('metrics'));
return parseMetrics(data);
Expand All @@ -144,4 +150,4 @@ export default class DltApi extends DltInterface {
}

/* This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences) */
© Copyright Utrecht University (Department of Information and Computing Sciences) */
4 changes: 3 additions & 1 deletion src/api/dlt/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export abstract class DltInterface {

abstract addPackage(pack: AddPackageForm): Promise<string | void>;

abstract getMostRecentVersion(pack: Package): Promise<string>;

abstract getMetrics(): Promise<Metrics>;

abstract getTrustScore(name: string, version: string): Promise<number | undefined>;
Expand Down Expand Up @@ -79,4 +81,4 @@ export const defaultMetrics: Metrics = {
};

/* This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences) */
© Copyright Utrecht University (Department of Information and Computing Sciences) */
8 changes: 6 additions & 2 deletions src/api/dlt/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export default class DltMock extends DltInterface {

async addPackage(pack: AddPackageForm) {
await fakeDelay();
return 'Success';
return 'Added jobs.';
}

async getMostRecentVersion(pack: Package): Promise<string> {
return "v7.8.9";
}

async getMetrics() {
Expand All @@ -73,4 +77,4 @@ export default class DltMock extends DltInterface {
}

/* This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences) */
© Copyright Utrecht University (Department of Information and Computing Sciences) */
137 changes: 86 additions & 51 deletions src/components/AddPackageComponent.vue
Original file line number Diff line number Diff line change
@@ -1,62 +1,68 @@
<template>
<va-modal
v-model="showAddedModal"
hide-default-actions
overlay-opacity="0.2"
>
<template #header>
<h2>Package added</h2>
</template>
<div>Your package has been added</div>
<template #footer>
<va-button @click="showAddedModal = false">
Close
</va-button>
</template>
</va-modal>
<PopUpMessage v-model="showAddedModal" title="Package added">
Package {{ job.name }} with version {{ job.release }} has been added
</PopUpMessage>

<va-modal
v-model="showFieldEmpty"
hide-default-actions
overlay-opacity="0.2"
>
<template #header>
<h2>Field empty</h2>
</template>
<div>One or more fields have been left empty.</div>
<template #footer>
<va-button @click="showFieldEmpty = false">
Close
</va-button>
</template>
</va-modal>
<PopUpMessage v-model="showFieldEmpty" title="Field empty">
One or more fields have been left empty.
</PopUpMessage>

<PopUpMessage v-model="showAlreadyAdded" title="Already added" @button-clicked="showPackage">
Package {{ job.name }} with version {{ job.release }} already in system, click close to show.
</PopUpMessage>

<PopUpMessage v-model="showError" title="Error retreiving most recent version">
Can't retreive most recent version from version.
</PopUpMessage>

<va-form>
<div class="row">
<va-input v-model="job.platform" :rules="[validateRequired]" class="flex xs6" label="Platform"/>
<va-input v-model="job.owner" :rules="[validateRequired]" class="flex xs6" label="Owner"/>
<va-input v-model="job.name" :rules="[validateRequired]" class="flex xs6" label="Name"/>
<va-input v-model="job.release" :rules="[validateRequired]" class="flex xs6" label="Version"/>
<va-input
v-model="job.platform"
:rules="[validateRequired]"
class="flex xs6"
label="Platform"
/>
<va-input
v-model="job.owner"
:rules="[validateRequired]"
class="flex xs6"
label="Owner"
/>
<va-input
v-model="job.name"
:rules="[validateRequired]"
class="flex xs6"
label="Name"
/>
<va-input
v-model="job.release"
class="flex xs6"
label="Version"
placeholder="leave empty for most recent version"
/>
<div class="flex xs12">
<va-button type="submit" @click="addPackage">Submit</va-button>
<div v-if="response">
<p>{{ response }}</p>
</div>
<va-button :loading="isLoading" type="submit" @click="addPackage">Submit</va-button>
</div>
</div>
</va-form>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import router from '@/router';
import PopUpMessage from '@/components/PopUpMessage.vue';

export default defineComponent({
name: 'add-package-component',
components: { PopUpMessage },
data() {
return {
showAddedModal:false,
showAddedModal: false,
showAlreadyAdded: false,
showError: false,
showFieldEmpty: false,
response: '',
isLoading: false,
job: {
platform: '',
owner: '',
Expand All @@ -67,26 +73,55 @@ export default defineComponent({
},
methods: {
async addPackage() {
if(this.job.platform.length>0 && this.job.owner.length>0 && this.job.name.length>0 && this.job.release.length>0){
const result = await this.$dltApi.addPackage(this.job);

if (typeof result === 'string') {
if(result=="Added jobs.") this.showAddedModal=true;
this.isLoading = true;
if (this.job.platform.length > 0 && this.job.owner.length > 0 && this.job.name.length > 0) {
// if no release was specified grab the latest one
if (this.job.release.length === 0) {
const version = await this.$dltApi.getMostRecentVersion({
platform: this.job.platform,
owner: this.job.owner,
name: this.job.name,
versions: [],
});
if (version === '') {
this.isLoading = false;
this.showError = true;
return;
}
this.job.release = version;
}

// check if the package is already in the system
const pack = await this.$dltApi.getPackage(this.job.name);
if (pack.versions.includes(this.job.release)) {
this.showAlreadyAdded = true;
} else {
const result = await this.$dltApi.addPackage(this.job);

if (typeof result === 'string') {
if (result === 'Added jobs.') this.showAddedModal = true;
}
}
} else {
this.showFieldEmpty=true;
this.showFieldEmpty = true;
}

this.isLoading = false;
},
// TODO: Move to generalized validation system
validateRequired(value: string) {
return (value && value.length > 0) || 'Field is required';
},
showPackage() {
router.push({
name: 'Package with Version',
params: {
name: this.job.name,
version: this.job.release,
},
});
},
},
});
</script>

<style scoped>
</style>
<!-- This program has been developed by students from the bachelor Computer Science at Utrecht University within the Software Project course.
© Copyright Utrecht University (Department of Information and Computing Sciences) -->
© Copyright Utrecht University (Department of Information and Computing Sciences) -->
18 changes: 18 additions & 0 deletions src/components/PopUpMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup lang="ts">
/* eslint-disable no-undef */
defineProps<{ title: string }>();
const enabled = defineModel<boolean>();
defineEmits(['button-clicked']);
</script>

<template>
<va-modal v-model="enabled" hide-default-actions overlay-opacity="0.2">
<template #header>
<h2>{{ title }}</h2>
</template>
<div><slot></slot></div>
<template #footer>
<va-button @click="enabled = false; $emit('button-clicked')"> Close </va-button>
</template>
</va-modal>
</template>
Loading
Loading