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

VULCAN- 565: Add latest release version tag to Navbar component #567

Merged
merged 2 commits into from
May 2, 2023
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
46 changes: 44 additions & 2 deletions app/javascript/components/navbar/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
<b-navbar toggleable="lg" type="dark" variant="dark">
<b-navbar-brand id="heading" href="/">
<i class="mdi mdi-radar" aria-hidden="true" />
VULCAN
VULCAN <span class="latest-release">{{ currentVersion }}</span>
</b-navbar-brand>

<b-navbar-toggle target="nav-collapse" />

<b-collapse id="nav-collapse" is-nav>
Expand Down Expand Up @@ -34,12 +33,22 @@
</div>
</b-collapse>
</b-navbar>
<b-alert
dismissible
fade
:show="updateAvailable"
class="text-center"
@dismissed="updateAvailable = false"
>
New version: Vulcan {{ latestRelease }} is now available!!
</b-alert>
</div>
</template>

<script>
import NavbarItem from "./NavbarItem.vue";
import SrgIdSearch from "./SrgIdSearch.vue";
import { version } from "../../../../package.json";

export default {
name: "Navbar",
Expand All @@ -66,6 +75,35 @@ export default {
required: false,
},
},
data() {
return {
latestRelease: "",
currentVersion: version,
updateAvailable: false,
};
},
mounted() {
this.fetchLatestRelease();
},
methods: {
fetchLatestRelease() {
const owner = "mitre";
const repo = "vulcan";
// Make the API request to fetch the latest release
fetch(`https://api.github.com/repos/${owner}/${repo}/releases/latest`)
.then((response) => response.json())
.then((data) => {
this.latestRelease = data.tag_name.substring(1);
this.updateAvailable = this.checkUpdateAvailable();
})
.catch((error) => {
this.latestRelease = "";
});
},
checkUpdateAvailable() {
return this.latestRelease.trim() !== "" && this.latestRelease !== this.currentVersion;
},
},
};
</script>

Expand All @@ -75,6 +113,10 @@ export default {
font-weight: 700;
letter-spacing: 1px;
}

.latest-release {
font-size: 0.6em;
}
.right-container {
gap: 32px;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"vue-template-compiler": "^2.6.11",
"vue-turbolinks": "^2.1.0"
},
"version": "0.1.0",
"version": "2.1.1",
"devDependencies": {
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.3.0",
Expand Down