Skip to content

Commit dc88f4c

Browse files
authored
Add Repositories list (#48)
* Add repositories tab * Fix unlocking installer if job was not created
2 parents 43792af + eaa89b1 commit dc88f4c

File tree

13 files changed

+300
-19
lines changed

13 files changed

+300
-19
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ All notable changes to `cybercog/laravel-paket` will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- ([#48]) Added repositories tab
10+
711
## [1.4.0]
812

913
### Added
1014

11-
- ([#39]) Add jobs deletion
12-
- ([#47]) Add job status badge in top menu
15+
- ([#39]) Added jobs deletion
16+
- ([#47]) Added job status badge in top menu
1317
- ([#42]) Lock installer when Job in progress
1418
- ([#47]) Unlock installer when Job in progress
1519

@@ -53,6 +57,7 @@ All notable changes to `cybercog/laravel-paket` will be documented in this file.
5357
[1.2.0]: https://github.com/cybercog/laravel-paket/compare/1.1.0...1.2.0
5458
[1.1.0]: https://github.com/cybercog/laravel-paket/compare/1.0.0...1.1.0
5559

60+
[#48]: https://github.com/cybercog/laravel-paket/pull/48
5661
[#47]: https://github.com/cybercog/laravel-paket/pull/47
5762
[#42]: https://github.com/cybercog/laravel-paket/pull/42
5863
[#39]: https://github.com/cybercog/laravel-paket/pull/39

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"php": "^7.1.3",
4242
"ext-json": "*",
4343
"illuminate/support": "5.6.*|5.7.*|5.8.*|^6.0",
44-
"mcstreetguy/composer-parser": "^1.0"
44+
"mcstreetguy/composer-parser": "^1.0.1"
4545
},
4646
"require-dev": {
4747
"friendsofphp/php-cs-fixer": "^2.10",

resources/js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ new Vue({
3333
// Need it to run jobs state checker after page reload
3434
await this.$store.dispatch('autoRefreshJobs');
3535
await this.$store.dispatch('collectRequirements');
36+
await this.$store.dispatch('collectRepositories');
3637
},
3738
},
3839
});
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<template>
2+
<div>
3+
<span
4+
class="bg-gray-200 border-b-2 border-gray-400 px-2 py-1 text-sm font-semibold font-mono tracking-wide text-gray-700 mr-2"
5+
v-text="type"
6+
></span>
7+
<span v-text="getTitle()"></span>
8+
<div>
9+
<div v-for="(option, optionName) in options">
10+
<div v-if="typeof option === 'object'" v-for="(optionValue, optionKey) in option" class="text-sm mt-4">
11+
<span class="font-semibold">options.{{ optionName }}.{{ optionKey }}:</span> {{ optionValue }}
12+
</div>
13+
<div v-if="typeof option !== 'object'" class="text-sm mt-4">
14+
<span class="font-semibold">options.{{ optionName }}:</span> {{ option }}
15+
</div>
16+
</div>
17+
</div>
18+
<div v-if="package">
19+
<div v-for="(distValue, distKey) in package.dist" class="text-sm mt-4">
20+
<span class="font-semibold">package.dist.{{ distKey }}:</span> {{ distValue }}
21+
</div>
22+
<div v-for="(sourceValue, sourceKey) in package.source" class="text-sm mt-4">
23+
<span class="font-semibold">package.source.{{ sourceKey }}:</span> {{ sourceValue }}
24+
</div>
25+
</div>
26+
</div>
27+
</template>
28+
29+
<script>
30+
export default {
31+
props: {
32+
repository: {
33+
type: Object,
34+
required: true,
35+
},
36+
},
37+
38+
mounted() {
39+
this.type = this.repository.type || null;
40+
this.url = this.repository.url || null;
41+
this.options = this.repository.options || [];
42+
this.package = this.repository.package || null;
43+
},
44+
45+
data() {
46+
return {
47+
type: null,
48+
url: null,
49+
options: [],
50+
package: null,
51+
}
52+
},
53+
54+
methods: {
55+
getTitle() {
56+
if (this.url !== null) {
57+
return this.url;
58+
}
59+
60+
if (this.package !== null) {
61+
return `${this.package.name} ${this.getPackageVersion()}`;
62+
}
63+
64+
return null;
65+
},
66+
67+
getPackageVersion() {
68+
if (this.package.version.substr(0, 1) === 'v') {
69+
return this.package.version;
70+
}
71+
72+
return `v${this.package.version}`;
73+
},
74+
},
75+
}
76+
</script>

resources/js/components/Requirement/InstallForm.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
:disabled="isDisabled()"
1515
v-text="getButtonText()"
1616
v-on:click="install()"
17-
>
18-
Install
19-
</button>
17+
></button>
2018
</div>
2119
</template>
2220

resources/js/components/TopMenu.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<router-link active-class="text-indigo-900 border-indigo-700 border-b-2" :to="{name: 'requirements'}" class="block py-3 lg:inline-block lg:mt-0 hover:text-indigo-900 mr-4">
2525
Requirements
2626
</router-link>
27+
<router-link active-class="text-indigo-900 border-indigo-700 border-b-2" :to="{name: 'repositories'}" class="block py-3 lg:inline-block lg:mt-0 hover:text-indigo-900 mr-4">
28+
Repositories
29+
</router-link>
2730
<router-link active-class="text-indigo-900 border-indigo-700 border-b-2" :to="{name: 'jobs'}" class="block py-3 lg:inline-block lg:mt-0 hover:text-indigo-900">
2831
Jobs
2932
<span :class="getJobsBadgeClass()"></span>

resources/js/routes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default [
2222
component: require('./screens/requirements/index').default,
2323
},
2424

25+
{
26+
path: '/repositories',
27+
name: 'repositories',
28+
component: require('./screens/repositories/index').default,
29+
},
30+
2531
{
2632
path: '/jobs',
2733
name: 'jobs',
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<template>
2+
<div class="container mx-auto mt-6">
3+
<h1 class="text-2xl">Repositories</h1>
4+
5+
<div v-if="getRepositories().length === 0" class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 mt-6 shadow" role="alert">
6+
<p class="font-bold">Repositories list is empty</p>
7+
<p>You can't install new packages without repositories!</p>
8+
</div>
9+
10+
<div v-for="repository in getRepositories()" class="rounded overflow-hidden shadow mt-3 p-4">
11+
<repository :repository="repository"/>
12+
</div>
13+
</div>
14+
</template>
15+
16+
<script>
17+
import Repository from '../../components/Repository/Repository';
18+
19+
export default {
20+
components: {
21+
Repository,
22+
},
23+
24+
mounted() {
25+
this.fetchData();
26+
},
27+
28+
methods: {
29+
async fetchData() {
30+
await this.$store.dispatch('collectRepositories');
31+
},
32+
33+
getRepositories() {
34+
return this.$store.getters.getRepositories();
35+
},
36+
},
37+
}
38+
</script>

resources/js/store.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const state = {
99
isInstallerLocked: false,
1010
installerCurrentJob: null,
1111
requirements: [],
12+
repositories: [],
1213
jobs: [],
1314
protectedRequirements: [
1415
'php',
@@ -40,9 +41,12 @@ const actions = {
4041
// Need this pre-lock to work with `sync` queue
4142
context.commit('lockInstaller', payload);
4243

43-
const response = await Axios.post(this.getters.getUrl('/api/jobs'), payload);
44-
45-
context.commit('lockInstaller', response.data);
44+
try {
45+
const response = await Axios.post(this.getters.getUrl('/api/jobs'), payload);
46+
context.commit('lockInstaller', response.data);
47+
} catch (exception) {
48+
context.commit('unlockInstaller');
49+
}
4650

4751
this.dispatch('collectRequirements');
4852
this.dispatch('collectJobs');
@@ -52,6 +56,20 @@ const actions = {
5256
await Axios.delete(this.getters.getUrl(`/api/jobs/${payload.id}`));
5357
},
5458

59+
async collectRepositories() {
60+
const url = this.getters.getUrl('/api/repositories');
61+
62+
try {
63+
const response = await Axios.get(url);
64+
65+
if (response.status === 200) {
66+
this.state.repositories = response.data;
67+
}
68+
} catch (exception) {
69+
console.warn(`Cannot fetch ${url}`);
70+
}
71+
},
72+
5573
async collectJobs() {
5674
const url = this.getters.getUrl('/api/jobs');
5775

@@ -103,6 +121,10 @@ const getters = {
103121
return window.location.origin + '/' + window.Paket.baseUri + uri;
104122
},
105123

124+
getRepositories: (state, getters) => () => {
125+
return state.repositories;
126+
},
127+
106128
getJobs: (state, getters) => () => {
107129
return state.jobs;
108130
},

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
use Illuminate\Support\Facades\Route;
1515

1616
Route::prefix('api')->namespace('Api')->name('paket.api.')->group(function () {
17+
Route::get('repositories')
18+
->uses('Repositories\CollectAction')
19+
->name('repositories.collect');
20+
1721
Route::get('requirements')
1822
->uses('Requirements\CollectAction')
1923
->name('requirements.collect');

0 commit comments

Comments
 (0)