Skip to content

Commit

Permalink
Update to read app version from package.json and display an alert if …
Browse files Browse the repository at this point in the history
…new version available

Signed-off-by: Vanessa Fotso <vfotso@mitre.org>
  • Loading branch information
vanessuniq committed May 2, 2023
1 parent 507f036 commit cffbe1e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 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 <span class="latest-release">{{ latestRelease }}</span>
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 Down Expand Up @@ -69,6 +78,8 @@ export default {
data() {
return {
latestRelease: "",
currentVersion: version,
updateAvailable: false,
};
},
mounted() {
Expand All @@ -78,18 +89,20 @@ export default {
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;
this.latestRelease = data.tag_name.substring(1);
this.updateAvailable = this.checkUpdateAvailable();
})
.catch((error) => {
// console.error("Error fetching latest release:", error);
this.latestRelease = "";
});
},
checkUpdateAvailable() {
return this.latestRelease.trim() !== "" && this.latestRelease !== this.currentVersion;
},
},
};
</script>
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

0 comments on commit cffbe1e

Please sign in to comment.