Skip to content

Commit

Permalink
Added a update and copy bundle assets
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavobascope committed Oct 21, 2024
1 parent d97c4eb commit a1d9acf
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 31 deletions.
3 changes: 2 additions & 1 deletion ProcessMaker/Http/Controllers/Api/DevLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ public function deleteBundle(Bundle $bundle)

public function installRemoteBundle(Request $request, DevLink $devLink, $remoteBundleId)
{
$updateType = $request->input('updateType', 'update');
DevLinkInstall::dispatch(
$request->user()->id,
$devLink->id,
$remoteBundleId,
'update'
$updateType
);
}

Expand Down
21 changes: 14 additions & 7 deletions ProcessMaker/Models/DevLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function remoteAssetsListing($request)
);
}

public function installRemoteBundle($bundleId)
public function installRemoteBundle($bundleId, $updateType)
{
if (!$this->logger) {
$this->logger = new Logger();
Expand All @@ -129,30 +129,37 @@ public function installRemoteBundle($bundleId)
[
'name' => $bundleInfo['name'],
'published' => $bundleInfo['published'],
'locked' => $bundleInfo['locked'],
'version' => $bundleInfo['version'],
]
);

$this->logger->status('Installing bundle on the this instance');
$this->logger->setSteps($bundleExport['payloads']);

$options = [
'mode' => $updateType,
'saveAssetsMode' => 'saveAllAssets',
'isTemplate' => false,
];
$assets = [];
foreach ($bundleExport['payloads'] as $payload) {
$assets[] = $this->import($payload);
$assets[] = $this->import($payload, $options);
}

$this->logger->status('Syncing bundle assets');
$bundle->syncAssets($assets);
if ($updateType === 'update') {
$this->logger->status('Syncing bundle assets');
$bundle->syncAssets($assets);
}

$this->logger->addWarning('Test warning message');

$this->logger->setStatus('done');
}

private function import(array $payload)
private function import(array $payload, $options = null)
{
$importer = new Importer($payload, new Options([]), $this->logger);
$options = $options === null ? new Options([]) : new Options($options);
$importer = new Importer($payload, $options, $this->logger);
$manifest = $importer->doImport();

return $manifest[$payload['root']]->model;
Expand Down
8 changes: 0 additions & 8 deletions resources/js/admin/devlink/components/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,6 @@ const urlIsValid = computed(() => {
</b-button>
</div>
</div>
<b-modal
ref="confirmDeleteModal"
centered
title="Delete DevLink"
@ok="executeDelete"
>
<p>Are you sure you want to delete {{ selected?.name }}?</p>
</b-modal>

<b-modal
id="create"
Expand Down
56 changes: 55 additions & 1 deletion resources/js/admin/devlink/components/Instance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ const bundles = ref([]);
const filter = ref("");
const warnings = ref([]);
const showInstallModal = ref(false);
const confirmUpdateVersion = ref(null);
const selectedOption = ref('update');
const bundleAttributes = {
id: null,
name: '',
published: false,
};
const selected = ref(bundleAttributes);
const fields = [
{
key: 'name',
Expand Down Expand Up @@ -48,6 +56,11 @@ const closeModal = () => {
$("#warningsModal").modal("hide");
};
const updateVersionBundle = (bundle) => {
selected.value = bundle;
confirmUpdateVersion.value.show();
};
const load = () => {
ProcessMaker.apiClient
.get(`/devlink/${route.params.id}/remote-bundles?filter=${filter.value}`)
Expand Down Expand Up @@ -79,6 +92,16 @@ const install = (bundle) => {
}
});
};
const executeUpdate = (updateType) => {
showInstallModal.value = true;
ProcessMaker.apiClient
.post(`/devlink/${route.params.id}/remote-bundles/${selected.value.id}/install`, {
updateType,
})
.then((response) => {
// Handle the response as needed
});
};
</script>

Expand All @@ -100,7 +123,7 @@ const install = (bundle) => {
<div class="btn-menu-container">
<button
class="btn install-bundle-btn"
@click.prevent="install(data.item)"
@click.prevent="updateVersionBundle(data.item)"
>
<i class="fp-cloud-download-outline"></i>
</button>
Expand Down Expand Up @@ -128,6 +151,37 @@ const install = (bundle) => {
</div>
</div>
</div>
<b-modal
ref="confirmUpdateVersion"
centered
size="lg"
content-class="modal-style"
:title="$t('Update Bundle Version')"
:ok-title="$t('Continue')"
:cancel-title="$t('Cancel')"
@ok="executeUpdate(selectedOption)"
>
<div>
<p class="mb-4">Select how you want to update the bundle <strong>Testing Processes and Assets</strong></p>

<b-form-group>
<b-form-radio-group v-model="selectedOption" name="bundleUpdateOptions">
<b-form-radio
class="mb-4"
value="update"
>
{{ $t('Quick Update') }}
<p class="text-muted">{{ $t('The current bundle will be replaced completely for the new version immediately.') }}</p>
</b-form-radio>

<b-form-radio value="copy">
{{ $t('Copy Changes') }}
<p class="text-muted">{{ $t('Copy and update bundle.') }}</p>
</b-form-radio>
</b-form-radio-group>
</b-form-group>
</div>
</b-modal>
<b-modal id="install-progress" size="lg" v-model="showInstallModal" :title="$t('Installation Progress')" hide-footer>
<install-progress />
</b-modal>
Expand Down
43 changes: 30 additions & 13 deletions resources/js/admin/devlink/components/LocalBundles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import debounce from 'lodash/debounce';
import Origin from './Origin.vue';
import VersionCheck from './VersionCheck.vue';
import EllipsisMenu from '../../../components/shared/EllipsisMenu.vue';
import InstallProgress from './InstallProgress.vue';
import { useRouter, useRoute } from 'vue-router/composables';
const vue = getCurrentInstance().proxy;
Expand All @@ -14,6 +15,8 @@ const editModal = ref(null);
const confirmDeleteModal = ref(null);
const confirmIncreaseVersion = ref(null);
const confirmUpdateVersion = ref(null);
const selectedOption = ref('update');
const showInstallModal = ref(false);
const filter = ref("");
const actions = [
{ value: "increase-item", content: "Increase Version", conditional: "if(not(dev_link_id), true, false)" },
Expand Down Expand Up @@ -162,8 +165,15 @@ const executeDelete = () => {
});
};
const executeUpdate = () => {
return null;
const executeUpdate = (updateType) => {
showInstallModal.value = true;
ProcessMaker.apiClient
.post(`/devlink/${selected.value.dev_link_id}/remote-bundles/${selected.value.remote_id}/install`, {
updateType,
})
.then((response) => {
// Handle the response as needed
});
};
// Debounced function
Expand Down Expand Up @@ -200,8 +210,8 @@ const deleteWaring = computed(() => {
@click="createNewBundle"
class="new-button"
>
<i class="fas fa-plus-circle" style="padding-right: 8px;"></i>
{{ $t('Create Bundle') }}
<i class="fas fa-plus-circle" style="padding-right: 8px;"></i>
{{ $t('Create Bundle') }}
</b-button>
</div>
</div>
Expand All @@ -228,25 +238,29 @@ const deleteWaring = computed(() => {
<b-modal
ref="confirmUpdateVersion"
centered
size="lg"
content-class="modal-style"
:title="$t('Update Bundle Version')"
:ok-title="$t('Continue')"
:cancel-title="$t('Cancel')"
@ok="executeUpdate"
@ok="executeUpdate(selectedOption)"
>
<div>
<p>Select how you want to update the bundle <strong>Testing Processes and Assets</strong></p>
<p class="mb-4">Select how you want to update the bundle <strong>Testing Processes and Assets</strong></p>
<b-form-group>
<b-form-radio-group v-model="selectedOption" name="bundleUpdateOptions">
<b-form-radio value="quick-update">
Quick Update
<p class="text-muted">The current bundle will be replaced completely for the new version immediately.</p>
<b-form-radio
class="mb-4"
value="update"
>
{{ $t('Quick Update') }}
<p class="text-muted">{{ $t('The current bundle will be replaced completely for the new version immediately.') }}</p>
</b-form-radio>
<b-form-radio value="review-changes">
Review changes in bundle
<p class="text-muted">Check and compare the changes before updating the bundle.</p>
<b-form-radio value="copy">
{{ $t('Copy Changes') }}
<p class="text-muted">{{ $t('Copy and update bundle.') }}</p>
</b-form-radio>
</b-form-radio-group>
</b-form-group>
Expand All @@ -269,13 +283,16 @@ const deleteWaring = computed(() => {
<b-form-checkbox v-model="selected.published"></b-form-checkbox>
</b-form-group>
</b-modal>
<b-modal id="install-progress" size="lg" v-model="showInstallModal" :title="$t('Installation Progress')" hide-footer>
<install-progress />
</b-modal>
<div class="card local-bundles-card">
<b-table
hover
class="clickable"
@row-clicked="goToBundleAssets"
:items="bundles"
:fields="fields"
@row-clicked="goToBundleAssets"
>
<template #cell(name)="data">
{{ data.item.name }}
Expand Down
1 change: 0 additions & 1 deletion tests/Model/DevLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public function testInstallRemoteBundle()
'id' => 123,
'name' => 'Test Bundle',
'published' => true,
'locked' => false,
'version' => '5',
]),
'http://remote-instance.test/api/1.0/devlink/export-local-bundle/123' => Http::response([
Expand Down

0 comments on commit a1d9acf

Please sign in to comment.