diff --git a/cypress/fixtures/CounterAdrsAllRepos.json b/cypress/fixtures/CounterAdrsAllRepos.json
index 9482e11..2057c1b 100644
--- a/cypress/fixtures/CounterAdrsAllRepos.json
+++ b/cypress/fixtures/CounterAdrsAllRepos.json
@@ -1,3 +1,3 @@
{
- "counter": "42"
+ "counter": "4"
}
\ No newline at end of file
diff --git a/cypress/fixtures/CounterAdrsPerRepo.json b/cypress/fixtures/CounterAdrsPerRepo.json
index 799d15e..2057c1b 100644
--- a/cypress/fixtures/CounterAdrsPerRepo.json
+++ b/cypress/fixtures/CounterAdrsPerRepo.json
@@ -1,3 +1,3 @@
{
- "counter": "14"
+ "counter": "4"
}
\ No newline at end of file
diff --git a/cypress/fixtures/CounterDiffAllRepos.json b/cypress/fixtures/CounterDiffAllRepos.json
index 4adb309..2057c1b 100644
--- a/cypress/fixtures/CounterDiffAllRepos.json
+++ b/cypress/fixtures/CounterDiffAllRepos.json
@@ -1,3 +1,3 @@
{
- "counter": "30"
+ "counter": "4"
}
\ No newline at end of file
diff --git a/cypress/fixtures/CounterDiffPerRepo.json b/cypress/fixtures/CounterDiffPerRepo.json
index ce1ca25..2057c1b 100644
--- a/cypress/fixtures/CounterDiffPerRepo.json
+++ b/cypress/fixtures/CounterDiffPerRepo.json
@@ -1,3 +1,3 @@
{
- "counter": "8"
+ "counter": "4"
}
\ No newline at end of file
diff --git a/cypress/integration/adrManagerTest/EmpiricalAnalysis.js b/cypress/integration/adrManagerTest/EmpiricalAnalysis.js
index 515d8dc..fdd52e3 100644
--- a/cypress/integration/adrManagerTest/EmpiricalAnalysis.js
+++ b/cypress/integration/adrManagerTest/EmpiricalAnalysis.js
@@ -10,6 +10,7 @@ context("Should test empirical add and open function of adr-manager", () => {
cy.get('[data-cy=addRepo]').click();
cy.intercept('GET', '**/user/repos**').as('getRepos');
+ cy.wait(5000);
cy.wait('@getRepos').its('response.statusCode').should('eq', 200);
cy.writeFile('cypress/fixtures/CounterDiffPerRepo.json', { counter: "0" });
cy.writeFile('cypress/fixtures/CounterAdrsPerRepo.json', { counter: "0" });
diff --git a/package-lock.json b/package-lock.json
index 73037b9..baac67b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3298,16 +3298,6 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true
},
- "ansi-styles": {
- "version": "4.3.0",
- "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
- "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
- "dev": true,
- "optional": true,
- "requires": {
- "color-convert": "^2.0.1"
- }
- },
"cacache": {
"version": "13.0.1",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-13.0.1.tgz",
@@ -3334,34 +3324,6 @@
"unique-filename": "^1.1.1"
}
},
- "chalk": {
- "version": "4.1.0",
- "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
- "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
- "dev": true,
- "optional": true,
- "requires": {
- "ansi-styles": "^4.1.0",
- "supports-color": "^7.1.0"
- }
- },
- "color-convert": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
- "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
- "dev": true,
- "optional": true,
- "requires": {
- "color-name": "~1.1.4"
- }
- },
- "color-name": {
- "version": "1.1.4",
- "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
- "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
- "dev": true,
- "optional": true
- },
"find-cache-dir": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.1.tgz",
@@ -3383,25 +3345,6 @@
"path-exists": "^4.0.0"
}
},
- "has-flag": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
- "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
- "dev": true,
- "optional": true
- },
- "loader-utils": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
- "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
- "dev": true,
- "optional": true,
- "requires": {
- "big.js": "^5.2.2",
- "emojis-list": "^3.0.0",
- "json5": "^2.1.2"
- }
- },
"locate-path": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
@@ -3466,16 +3409,6 @@
"minipass": "^3.1.1"
}
},
- "supports-color": {
- "version": "7.2.0",
- "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
- "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
- "dev": true,
- "optional": true,
- "requires": {
- "has-flag": "^4.0.0"
- }
- },
"terser-webpack-plugin": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-2.3.8.tgz",
@@ -3492,18 +3425,6 @@
"terser": "^4.6.12",
"webpack-sources": "^1.4.3"
}
- },
- "vue-loader-v16": {
- "version": "npm:vue-loader@16.1.2",
- "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.1.2.tgz",
- "integrity": "sha512-8QTxh+Fd+HB6fiL52iEVLKqE9N1JSlMXLR92Ijm6g8PZrwIxckgpqjPDWRP5TWxdiPaHR+alUWsnu1ShQOwt+Q==",
- "dev": true,
- "optional": true,
- "requires": {
- "chalk": "^4.1.0",
- "hash-sum": "^2.0.0",
- "loader-utils": "^2.0.0"
- }
}
}
},
@@ -17350,6 +17271,87 @@
}
}
},
+ "vue-loader-v16": {
+ "version": "npm:vue-loader@16.1.2",
+ "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.1.2.tgz",
+ "integrity": "sha512-8QTxh+Fd+HB6fiL52iEVLKqE9N1JSlMXLR92Ijm6g8PZrwIxckgpqjPDWRP5TWxdiPaHR+alUWsnu1ShQOwt+Q==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "chalk": "^4.1.0",
+ "hash-sum": "^2.0.0",
+ "loader-utils": "^2.0.0"
+ },
+ "dependencies": {
+ "ansi-styles": {
+ "version": "4.3.0",
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
+ "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "color-convert": "^2.0.1"
+ }
+ },
+ "chalk": {
+ "version": "4.1.0",
+ "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz",
+ "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "ansi-styles": "^4.1.0",
+ "supports-color": "^7.1.0"
+ }
+ },
+ "color-convert": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
+ "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "color-name": "~1.1.4"
+ }
+ },
+ "color-name": {
+ "version": "1.1.4",
+ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
+ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
+ "dev": true,
+ "optional": true
+ },
+ "has-flag": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
+ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
+ "dev": true,
+ "optional": true
+ },
+ "loader-utils": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
+ "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "big.js": "^5.2.2",
+ "emojis-list": "^3.0.0",
+ "json5": "^2.1.2"
+ }
+ },
+ "supports-color": {
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
+ "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
+ "dev": true,
+ "optional": true,
+ "requires": {
+ "has-flag": "^4.0.0"
+ }
+ }
+ }
+ },
"vue-observe-visibility": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-0.4.6.tgz",
diff --git a/src/components/DialogCommit.vue b/src/components/DialogCommit.vue
index 6c56e4c..da0926f 100644
--- a/src/components/DialogCommit.vue
+++ b/src/components/DialogCommit.vue
@@ -224,7 +224,8 @@ export default {
type: Boolean,
required: false,
default: false
- }
+ },
+ repo: String
},
data: () => ({
showDialog: false,
@@ -285,7 +286,7 @@ export default {
setUserInfo() {
getUserName(this.currUser)
.then((res) => {
- this.name = res.name;
+ this.name = res.login;
})
.catch((error) => {
this.errorRequest = true;
@@ -309,22 +310,22 @@ export default {
},
setRepoInfo() {
- let repoInfos = store.getRepoInfoForCommit();
+ let repoInfos = store.getRepoInfoForCommit(this.repo);
this.currUser = repoInfos.userName;
this.currRepo = repoInfos.repoName;
this.branch = repoInfos.activeBranch;
},
setFilesForCommit() {
- this.changedFiles = store.changedFilesInRepo();
+ this.changedFiles = store.changedFilesInRepo(this.repo);
if (this.changedFiles.length > 0) {
this.changedFileBool = true;
}
- this.newFiles = store.newFilesInRepo();
+ this.newFiles = store.newFilesInRepo(this.repo);
if (this.newFiles.length > 0) {
this.newFileBool = true;
}
- this.deletedFiles = store.deletedFilesInRepo();
+ this.deletedFiles = store.deletedFilesInRepo(this.repo);
if (this.deletedFiles.length > 0) {
this.deletedFileBool = true;
}
@@ -542,7 +543,7 @@ export default {
}, 60000);
this.loading = false;
if (!this.errorRequest) {
- store.updateLocalStorageAfterCommit(this.filesPushed);
+ store.updateLocalStorageAfterCommit(this.filesPushed, this.repo);
this.$alert("Successfully pushed", "Success", "success");
}
})
diff --git a/src/components/FileExplorer.vue b/src/components/FileExplorer.vue
index a812da0..6d02053 100644
--- a/src/components/FileExplorer.vue
+++ b/src/components/FileExplorer.vue
@@ -18,7 +18,7 @@
diff --git a/src/plugins/store.js b/src/plugins/store.js
index df9681b..0506232 100644
--- a/src/plugins/store.js
+++ b/src/plugins/store.js
@@ -1,377 +1,464 @@
-/**
+/**
* The store contains the global state of the ADR-Manager and can be used to communicate between components.
- *
+ *
* Emitted Events:
- *
+ *
* 'open-adr'
* - {object} adr object
* 'set-mode'
* - {string} mode (either 'basic', 'advanced' or 'profesional')
*/
-
-import Vue from 'vue'
-import _ from 'lodash'
-import { ArchitecturalDecisionRecord, Repository } from './classes'
-import { adr2md, naturalCase2snakeCase } from './parser'
+import Vue from "vue";
+import _ from "lodash";
+import { ArchitecturalDecisionRecord, Repository } from "./classes";
+import { adr2md, naturalCase2snakeCase } from "./parser";
export const store = new Vue({
- data: {
- currentRepository: undefined,
- currentBranch: undefined,
- currentlyEditedAdr: undefined,
- addedRepositories: [],
- mode: 'basic'
+ data: {
+ currentRepository: undefined,
+ currentBranch: undefined,
+ currentlyEditedAdr: undefined,
+ addedRepositories: [],
+ mode: "basic"
+ },
+
+ created() {
+ console.log("Created Store!");
+ this.reload();
+ },
+
+ methods: {
+ /** Loads all data from local storage.
+ */
+ reload() {
+ /* Load data from local storage. */
+ this.addedRepositories = [];
+ let addedRepos = localStorage.getItem("addedRepositories");
+ if (addedRepos !== null) {
+ addedRepos = JSON.parse(addedRepos);
+ // Validate storage
+ if (isValidRepoList(addedRepos)) {
+ this.addRepositories(
+ addedRepos.map((repo) =>
+ Repository.constructFromString(JSON.stringify(repo))
+ )
+ );
+ } else {
+ console.log("Invalid repos: ", addedRepos);
+ }
+ }
+ /* Load mode from local storage */
+ this.mode = localStorage.getItem("mode") || "basic";
},
- created() {
- console.log('Created Store!');
- this.reload();
+ /**
+ * Write the current value of the added repositories list array into the local storage.
+ * Should be done regularly.
+ */
+ updateLocalStorageRepositories: function() {
+ localStorage.setItem(
+ "addedRepositories",
+ JSON.stringify(this.addedRepositories)
+ );
},
- methods: {
- /** Loads all data from local storage.
- */
- reload() {
- /* Load data from local storage. */
- this.addedRepositories = [];
- let addedRepos = localStorage.getItem('addedRepositories');
- if (addedRepos !== null) {
- addedRepos = JSON.parse(addedRepos);
- // Validate storage
- if (isValidRepoList(addedRepos)) {
- this.addRepositories(addedRepos.map((repo) => Repository.constructFromString(JSON.stringify(repo))));
- } else {
- console.log('Invalid repos: ', addedRepos);
- }
- }
- /* Load mode from local storage */
- this.mode = localStorage.getItem('mode') || 'basic';
- },
-
- /**
- * Write the current value of the added repositories list array into the local storage.
- * Should be done regularly.
- */
- updateLocalStorageRepositories: function () {
- localStorage.setItem('addedRepositories', JSON.stringify(this.addedRepositories));
- },
-
- /** Adds the repositories to the added repositories.
- * If no ADR is currently edited, open one.
- * @param {Array} repoList - a list of repositories
- */
- addRepositories(repoList) {
- console.log('Add Repositories to store', repoList);
- let alreadyAddedRepos = repoList.filter(repoToAdd => this.addedRepositories.map(repo => (repo.fullName)).includes(repoToAdd.fullName) );
- if (alreadyAddedRepos.length > 0) {
- throw 'I won\'t add an already added repository to the store! ' + alreadyAddedRepos.map(repo => repo.fullName).join(', ')
- }
- this.addedRepositories = this.addedRepositories.concat(repoList);
- this.updateLocalStorageRepositories();
- this.assertSomeAdrIsOpened();
- },
-
- /** Removes the repository from the added repositories.
- * If the currently edited adr is in that repository, open another one.
- * @param {object} repoToRemove
- */
- removeRepository(repoToRemove) {
- this.addedRepositories = this.addedRepositories.filter((repo) => (repo.fullName !== repoToRemove.fullName));
- this.assertSomeAdrIsOpened();
- this.updateLocalStorageRepositories();
- },
-
- /** Updates the repository with the same full name as the passed repository. */
- updateRepository(updatedRepository) {
- let index = this.addedRepositories.findIndex((repo) => (repo.fullName === updatedRepository.fullName));
- let oldRepo = this.addedRepositories[index];
- this.addedRepositories.splice(index, 1, updatedRepository);
- if (oldRepo.adrs.includes(this.currentlyEditedAdr)) {
- this.openAdr(updatedRepository.adrs.find((adr) => (adr.path === this.currentlyEditedAdr.path)))
- }
- this.updateLocalStorageRepositories();
- },
-
- /**Sets the active branch.
- *
- * @param {string} activeBranch
- */
- setActiveBranch(activeBranch) {
- this.activeBranch = activeBranch;
- },
-
- /**
- * Make sure that there is one ADR currently edited.
- * If there is no currently edited ADR (or it isn't valid), open some ADR.
- */
- assertSomeAdrIsOpened() {
- if (this.currentlyEditedAdr === undefined
- || !isValidAdr(this.currentlyEditedAdr)
- || !this.addedRepositories.some(repo => repo.adrs.includes(this.currentlyEditedAdr))) {
- this.currentlyEditedAdr = undefined;
- this.currentRepository = undefined;
- this.currentBranch = undefined;
- this.openAnyAdr();
- }
- },
-
- /**
- * Opens any ADR.
- */
- openAnyAdr() {
- let reposWithAdrs = this.addedRepositories.filter(repo => (repo.adrs && repo.adrs[0]));
- if (reposWithAdrs.length > 0) {
- let someAdr = reposWithAdrs[0].adrs[0];
- this.openAdr(someAdr);
- }
- },
-
- /**
- * Open the ADR with the specified name in the repository if it exists.
- * @param {string} repoFullName
- * @param {string} adrName
- * @returns the ADR iff it was found, else undefined
- */
- openAdrBy(repoFullName, adrName) {
- let repo = this.addedRepositories
- .find((repo) => repo.fullName === repoFullName);
- let adr;
- if (repo) {
- adr = repo.adrs
- .find(adr => {
- return adr.path.split('/').pop() === adrName;
- });
- }
- if (adr) {
- this.openAdr(adr);
- return adr;
- }
- return adr;
- },
-
- /**Opens the ADR.
- * Requires the adr parameter to be a valid ADR object and to be contained in one of the added repositories.
- *
- * @param {object} adr
- */
- openAdr: function (adr) {
- if (adr !== this.currentlyEditedAdr) {
- let repo = this.addedRepositories.find(repo => repo.adrs.includes(adr));
- if (isValidAdr(adr) && repo !== undefined) {
- this.currentRepository = repo;
- this.currentBranch = repo.activeBranch;
- this.currentlyEditedAdr = adr;
- console.log('Open ADR in store.js ', adr);
- this.$emit('open-adr', adr);
- } else {
- console.log('This is not a valid ADR', adr);
- }
- } else {
- console.log('I won\'t open the same ADR twice! D:');
- }
- },
-
- /**Sets the Markdown of the current ADR to the parameter string.
- * Updates the name of the Adr file to match the title of the ADR.
- * Also updates the local storage.
- *
- * @param {string} md
- */
- updateMdOfCurrentAdr(md) {
- this.currentlyEditedAdr.editedMd = md;
-
- /* Update the path of the file for now only for newly added files*/
- if (this.currentRepository && this.currentRepository.addedAdrs && this.currentRepository.addedAdrs.includes(this.currentlyEditedAdr)) {
- let path = this.currentlyEditedAdr.path.split('/');
- let title = md.split('\n')[0].replace(/^#+/, '').trim();
- path[path.length - 1] = this.currentlyEditedAdr.id.toString().padStart(4, '0') + '-' + naturalCase2snakeCase(title) + '.md';
- this.currentlyEditedAdr.path = path.join('/');
- }
+ /** Adds the repositories to the added repositories.
+ * If no ADR is currently edited, open one.
+ * @param {Array} repoList - a list of repositories
+ */
+ addRepositories(repoList) {
+ console.log("Add Repositories to store", repoList);
+ let alreadyAddedRepos = repoList.filter((repoToAdd) =>
+ this.addedRepositories
+ .map((repo) => repo.fullName)
+ .includes(repoToAdd.fullName)
+ );
+ if (alreadyAddedRepos.length > 0) {
+ throw "I won't add an already added repository to the store! " +
+ alreadyAddedRepos.map((repo) => repo.fullName).join(", ");
+ }
+ this.addedRepositories = this.addedRepositories.concat(repoList);
+ this.updateLocalStorageRepositories();
+ this.assertSomeAdrIsOpened();
+ },
- this.updateLocalStorageRepositories();
- },
+ /** Removes the repository from the added repositories.
+ * If the currently edited adr is in that repository, open another one.
+ * @param {object} repoToRemove
+ */
+ removeRepository(repoToRemove) {
+ this.addedRepositories = this.addedRepositories.filter(
+ (repo) => repo.fullName !== repoToRemove.fullName
+ );
+ this.assertSomeAdrIsOpened();
+ this.updateLocalStorageRepositories();
+ },
- /**Creates a new ADR in the specified repository.
+ /** Updates the repository with the same full name as the passed repository. */
+ updateRepository(updatedRepository) {
+ let index = this.addedRepositories.findIndex(
+ (repo) => repo.fullName === updatedRepository.fullName
+ );
+ let oldRepo = this.addedRepositories[index];
+ this.addedRepositories.splice(index, 1, updatedRepository);
+ if (oldRepo.adrs.includes(this.currentlyEditedAdr)) {
+ this.openAdr(
+ updatedRepository.adrs.find(
+ (adr) => adr.path === this.currentlyEditedAdr.path
+ )
+ );
+ }
+ this.updateLocalStorageRepositories();
+ },
+
+ /**Sets the active branch.
+ *
+ * @param {string} activeBranch
+ */
+ setActiveBranch(activeBranch) {
+ this.activeBranch = activeBranch;
+ },
+
+ /**
+ * Make sure that there is one ADR currently edited.
+ * If there is no currently edited ADR (or it isn't valid), open some ADR.
+ */
+ assertSomeAdrIsOpened() {
+ if (
+ this.currentlyEditedAdr === undefined ||
+ !isValidAdr(this.currentlyEditedAdr) ||
+ !this.addedRepositories.some((repo) =>
+ repo.adrs.includes(this.currentlyEditedAdr)
+ )
+ ) {
+ this.currentlyEditedAdr = undefined;
+ this.currentRepository = undefined;
+ this.currentBranch = undefined;
+ this.openAnyAdr();
+ }
+ },
+
+ /**
+ * Opens any ADR.
+ */
+ openAnyAdr() {
+ let reposWithAdrs = this.addedRepositories.filter(
+ (repo) => repo.adrs && repo.adrs[0]
+ );
+ if (reposWithAdrs.length > 0) {
+ let someAdr = reposWithAdrs[0].adrs[0];
+ this.openAdr(someAdr);
+ }
+ },
+
+ /**
+ * Open the ADR with the specified name in the repository if it exists.
+ * @param {string} repoFullName
+ * @param {string} adrName
+ * @returns the ADR iff it was found, else undefined
+ */
+ openAdrBy(repoFullName, adrName) {
+ let repo = this.addedRepositories.find(
+ (repo) => repo.fullName === repoFullName
+ );
+ let adr;
+ if (repo) {
+ adr = repo.adrs.find((adr) => {
+ return adr.path.split("/").pop() === adrName;
+ });
+ }
+ if (adr) {
+ this.openAdr(adr);
+ return adr;
+ }
+ return adr;
+ },
+
+ /**Opens the ADR.
+ * Requires the adr parameter to be a valid ADR object and to be contained in one of the added repositories.
+ *
+ * @param {object} adr
+ */
+ openAdr: function(adr) {
+ if (adr !== this.currentlyEditedAdr) {
+ let repo = this.addedRepositories.find((repo) =>
+ repo.adrs.includes(adr)
+ );
+ if (isValidAdr(adr) && repo !== undefined) {
+ this.currentRepository = repo;
+ this.currentBranch = repo.activeBranch;
+ this.currentlyEditedAdr = adr;
+ console.log("Open ADR in store.js ", adr);
+ this.$emit("open-adr", adr);
+ } else {
+ console.log("This is not a valid ADR", adr);
+ }
+ } else {
+ console.log("I won't open the same ADR twice! D:");
+ }
+ },
+
+ /**Sets the Markdown of the current ADR to the parameter string.
+ * Updates the name of the Adr file to match the title of the ADR.
+ * Also updates the local storage.
+ *
+ * @param {string} md
+ */
+ updateMdOfCurrentAdr(md) {
+ this.currentlyEditedAdr.editedMd = md;
+
+ /* Update the path of the file for now only for newly added files*/
+ if (
+ this.currentRepository &&
+ this.currentRepository.addedAdrs &&
+ this.currentRepository.addedAdrs.includes(this.currentlyEditedAdr)
+ ) {
+ let path = this.currentlyEditedAdr.path.split("/");
+ let title = md
+ .split("\n")[0]
+ .replace(/^#+/, "")
+ .trim();
+ path[path.length - 1] =
+ this.currentlyEditedAdr.id.toString().padStart(4, "0") +
+ "-" +
+ naturalCase2snakeCase(title) +
+ ".md";
+ this.currentlyEditedAdr.path = path.join("/");
+ }
+
+ this.updateLocalStorageRepositories();
+ },
+
+ /**Creates a new ADR in the specified repository.
*
* Get highest ID and adapt name of ADR based on title in Editor.
*
* @param {object} repo - must be one of the added repositories
* @returns the created adr if repo is added, undefined otherwise
*/
- createNewAdr: function (repo) {
- if (this.addedRepositories.includes(repo)) {
- let adr = ArchitecturalDecisionRecord.createNewAdr();
- let md = adr2md(adr);
- let id = Math.max(...repo.adrs.map((adr) => adr.id), -1) + 1;
- let newAdr = {
- originalMd: '',
- editedMd: md,
- id: id,
- path: "docs/adr/" + id.toString().padStart(4, "0") + "-" + adr.title + ".md",
- newAdr: true,
- };
- repo.addAdr(newAdr);
- this.updateLocalStorageRepositories();
- return newAdr;
- } else {
- return undefined;
- }
- },
-
- /**Deletes the ADR.
- * The ADR is removed from the adr list of the repository and appended to the list of deleted ADRs
- *
- * @param {object} adr
- * @param {object} repo
- */
- deleteAdr(adr, repo) {
- console.log("Deleting requested!", adr, repo);
- let adrIndexAdr = repo.adrs.findIndex((adrEl) => adrEl == adr);
- let adrIndexNewAdr = repo.addedAdrs.findIndex((adrEl) => adrEl == adr);
- if (!repo.deletedAdrs) {
- repo.deletedAdrs = [];
- }
-
- let file = repo.adrs.splice(adrIndexAdr, 1)[0];
- if (adrIndexNewAdr >= 0) {
- repo.addedAdrs.splice(adrIndexNewAdr, 1)[0];
- } else repo.deletedAdrs.push(file);
+ createNewAdr: function(repo) {
+ if (this.addedRepositories.includes(repo)) {
+ let adr = ArchitecturalDecisionRecord.createNewAdr();
+ let md = adr2md(adr);
+ let id = Math.max(...repo.adrs.map((adr) => adr.id), -1) + 1;
+ let newAdr = {
+ originalMd: "",
+ editedMd: md,
+ id: id,
+ path:
+ "docs/adr/" +
+ id.toString().padStart(4, "0") +
+ "-" +
+ adr.title +
+ ".md",
+ newAdr: true
+ };
+ repo.addAdr(newAdr);
this.updateLocalStorageRepositories();
- },
-
- /**Sets the current mode and emits the 'set-mode' event.
- *
- * @param {string} mode - the new mode (must be either 'basic', 'advanced' or 'professional')
- */
- setMode(mode) {
- if (["basic", "advanced", "professional"].includes(mode)) {
- // Double-check that passed mode is valid.
- console.log("Set mode to", mode);
- this.mode = mode;
- localStorage.setItem("mode", mode);
- this.$emit("set-mode", mode);
- } else {
- console.log("Error in Mode Selection");
- }
- },
-
- changedFilesInRepo() {
- let changedFiles = [];
- for (let changedFile of this.currentRepository.adrs) {
- if (!("newAdr" in changedFile))
- if (changedFile.editedMd != changedFile.originalMd) {
- changedFiles.push(this.dataStructureDataCommit(changedFile, "changed"));
+ return newAdr;
+ } else {
+ return undefined;
+ }
+ },
+
+ /**Deletes the ADR.
+ * The ADR is removed from the adr list of the repository and appended to the list of deleted ADRs
+ *
+ * @param {object} adr
+ * @param {object} repo
+ */
+ deleteAdr(adr, repo) {
+ console.log("Deleting requested!", adr, repo);
+ let adrIndexAdr = repo.adrs.findIndex((adrEl) => adrEl == adr);
+ let adrIndexNewAdr = repo.addedAdrs.findIndex((adrEl) => adrEl == adr);
+ if (!repo.deletedAdrs) {
+ repo.deletedAdrs = [];
+ }
+
+ let file = repo.adrs.splice(adrIndexAdr, 1)[0];
+ if (adrIndexNewAdr >= 0) {
+ repo.addedAdrs.splice(adrIndexNewAdr, 1)[0];
+ } else repo.deletedAdrs.push(file);
+ this.updateLocalStorageRepositories();
+ },
+
+ /**Sets the current mode and emits the 'set-mode' event.
+ *
+ * @param {string} mode - the new mode (must be either 'basic', 'advanced' or 'professional')
+ */
+ setMode(mode) {
+ if (["basic", "advanced", "professional"].includes(mode)) {
+ // Double-check that passed mode is valid.
+ console.log("Set mode to", mode);
+ this.mode = mode;
+ localStorage.setItem("mode", mode);
+ this.$emit("set-mode", mode);
+ } else {
+ console.log("Error in Mode Selection");
+ }
+ },
+
+ changedFilesInRepo(repoName) {
+ let changedFiles = [];
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let changedFile of repo.adrs) {
+ if (!("newAdr" in changedFile)) {
+ if (changedFile.editedMd != changedFile.originalMd) {
+ changedFiles.push(
+ this.dataStructureDataCommit(changedFile, "changed")
+ );
+ }
}
+ }
}
- return changedFiles;
- },
-
- deletedFilesInRepo() {
- let deletedFiles = [];
- for (let deletedFile of this.currentRepository.deletedAdrs) {
- deletedFiles.push({ path: deletedFile.path, title: deletedFile.path.split("/")[2], fileSelected: false, fileStatus: "deleted" });
+ }
+
+ return changedFiles;
+ },
+
+ deletedFilesInRepo(repoName) {
+ let deletedFiles = [];
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let deletedFile of repo.deletedAdrs) {
+ deletedFiles.push({
+ path: deletedFile.path,
+ title: deletedFile.path.split("/")[2],
+ fileSelected: false,
+ fileStatus: "deleted",
+ });
+ }
}
- return deletedFiles;
- },
-
- newFilesInRepo() {
- let newFiles = [];
- for (let newFile of this.currentRepository.addedAdrs) {
- newFiles.push(this.dataStructureDataCommit(newFile, "new"));
+ }
+ return deletedFiles;
+ },
+
+ newFilesInRepo(repoName) {
+ let newFiles = [];
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let newFile of repo.addedAdrs) {
+ newFiles.push(this.dataStructureDataCommit(newFile, "new"));
+ }
}
- return newFiles;
- },
-
- dataStructureDataCommit(file, fileType) {
- return {
- title: file.path.split("/")[2],
- value: file.editedMd,
- path: file.path,
- fileSelected: false,
- fileStatus: fileType
-
+ }
+ return newFiles;
+ },
+
+ dataStructureDataCommit(file, fileType) {
+ return {
+ title: file.path.split("/")[2],
+ value: file.editedMd,
+ path: file.path,
+ fileSelected: false,
+ fileStatus: fileType,
+ };
+ },
+
+ getRepoInfoForCommit(repoName) {
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ return {
+ userName: repo.fullName.split("/")[0],
+ repoName: repo.fullName.split("/")[1],
+ activeBranch: repo.activeBranch,
+ };
}
- },
-
- getRepoInfoForCommit() {
- return {
- userName: this.currentRepository.fullName.split("/")[0],
- repoName: this.currentRepository.fullName.split("/")[1],
- activeBranch: this.currentRepository.activeBranch
- };
- },
-
- updateLocalStorageAfterCommit(pushedFiles) {
- for (let file of pushedFiles) {
- switch (file.type) {
- case "new":
- this.handleUpdateLocalStorageNew(file);
- break;
- case "changed":
- this.handleUpdateLocalStorageChanged(file);
- break;
- case "deleted":
- this.handleUpdateLocalStorageDeleted(file);
- break;
- }
+ }
+ },
+
+ updateLocalStorageAfterCommit(pushedFiles, repoName) {
+ for (let file of pushedFiles) {
+ switch (file.type) {
+ case "new":
+ this.handleUpdateLocalStorageNew(file, repoName);
+ break;
+ case "changed":
+ this.handleUpdateLocalStorageChanged(file, repoName);
+ break;
+ case "deleted":
+ this.handleUpdateLocalStorageDeleted(file, repoName);
+ break;
}
- this.updateLocalStorageRepositories();
- },
-
- handleUpdateLocalStorageNew(file) {
- for (let repoEntry of this.currentRepository.addedAdrs) {
- if (file.path === repoEntry.path) {
- let index = this.currentRepository.addedAdrs.indexOf(repoEntry);
- this.currentRepository.addedAdrs.splice(index, 1);
+ }
+ this.updateLocalStorageRepositories();
+ },
+
+ handleUpdateLocalStorageNew(file, repoName) {
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let repoEntry of repo.addedAdrs) {
+ if (file.path === repoEntry.path) {
+ let index = repo.addedAdrs.indexOf(repoEntry);
+ repo.addedAdrs.splice(index, 1);
+ }
}
- }
- for (let repoEntry of this.currentRepository.adrs) {
- if (file.path === repoEntry.path) {
- delete repoEntry["newAdr"];
- repoEntry["originalMd"] = repoEntry.editedMd;
+ for (let repoEntry of repo.adrs) {
+ if (file.path === repoEntry.path) {
+ delete repoEntry["newAdr"];
+ repoEntry["originalMd"] = repoEntry.editedMd;
+ }
}
}
- },
-
- handleUpdateLocalStorageChanged(file) {
- for (let repoEntry of this.currentRepository.adrs) {
- if (file.path === repoEntry.path) {
- repoEntry.originalMd = repoEntry.editedMd;
+ }
+ },
+
+ handleUpdateLocalStorageChanged(file, repoName) {
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let repoEntry of repo.adrs) {
+ if (file.path === repoEntry.path) {
+ repoEntry.originalMd = repoEntry.editedMd;
+ }
}
}
- },
-
- handleUpdateLocalStorageDeleted(file) {
- for (let repoEntry of this.currentRepository.deletedAdrs) {
- if (file.path === repoEntry.path) {
- let index = this.currentRepository.deletedAdrs.indexOf(repoEntry);
- this.currentRepository.deletedAdrs.splice(index, 1);
+ }
+ },
+
+ handleUpdateLocalStorageDeleted(file, repoName) {
+ for (let repo of this.addedRepositories) {
+ if (repoName === repo.fullName) {
+ for (let repoEntry of repo.deletedAdrs) {
+ if (file.path === repoEntry.path) {
+ let index = repo.deletedAdrs.indexOf(repoEntry);
+ repo.deletedAdrs.splice(index, 1);
+ }
}
}
}
}
- });
+ }
+});
-/**Checks if each repo in the parameter array repos is a valid repository
+/**Checks if each repo in the parameter array repos is a valid repository
* (that can be displayed in the file explorer, etc.)
- *
- * A valid repoitory r must be an instance of the Reppository class and each adr in r.adrs must
+ *
+ * A valid repoitory r must be an instance of the Reppository class and each adr in r.adrs must
* have the attributes originalMd, editedMd and path where path is the local path inside the repository (i.e. starting with 'docs/adr')
- *
- * @param {object[]} repos
+ *
+ * @param {object[]} repos
*/
function isValidRepoList(repos) {
- return repos.every(repo => {
- let valid = _.has(repo, 'fullName') && _.has(repo, 'activeBranch') && _.has(repo, 'branches') &&_.has(repo, 'addedAdrs') && _.has(repo, 'deletedAdrs')
- && _.has(repo, 'adrs') && repo.adrs.every(isValidAdr);
- if (!valid) {
- console.log('Invalid repository', repo)
- }
- return valid;
- });
+ return repos.every((repo) => {
+ let valid =
+ _.has(repo, "fullName") &&
+ _.has(repo, "activeBranch") &&
+ _.has(repo, "branches") &&
+ _.has(repo, "addedAdrs") &&
+ _.has(repo, "deletedAdrs") &&
+ _.has(repo, "adrs") &&
+ repo.adrs.every(isValidAdr);
+ if (!valid) {
+ console.log("Invalid repository", repo);
+ }
+ return valid;
+ });
}
function isValidAdr(adr) {
- return _.has(adr, 'originalMd') && _.has(adr, 'editedMd') && _.has(adr, 'path');
-}
\ No newline at end of file
+ return (
+ _.has(adr, "originalMd") && _.has(adr, "editedMd") && _.has(adr, "path")
+ );
+}