Skip to content

Commit

Permalink
Download code.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Nov 30, 2023
1 parent d5c242e commit 927c877
Show file tree
Hide file tree
Showing 12 changed files with 570 additions and 29 deletions.
42 changes: 40 additions & 2 deletions uSync.Migrations.Client/Controllers/uSyncMigrationsController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using System.Net.Mime;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
Expand All @@ -10,6 +13,7 @@
using Umbraco.Extensions;

using uSync.BackOffice;
using uSync.BackOffice.Hubs;
using uSync.BackOffice.Services;
using uSync.Migrations.Core;
using uSync.Migrations.Core.Configuration;
Expand All @@ -31,7 +35,10 @@ public class uSyncMigrationsController : UmbracoAuthorizedApiController
private readonly ISyncMigrationConfigurationService _profileConfigService;
private readonly ISyncMigrationStatusService _migrationStatusService;

private readonly ISyncMigrationPackService _packService;

private readonly uSyncService _uSyncService;
private readonly IHubContext<SyncHub> _hubContext;
private readonly SyncFileService _syncFileService;
private readonly string _tempPath;
private readonly string _siteRoot;
Expand All @@ -44,7 +51,9 @@ public uSyncMigrationsController(
SyncFileService syncFileService,
ISyncMigrationFileService migrationFileService,
IShortStringHelper shortStringHelper,
ISyncMigrationStatusService migrationStatusService)
ISyncMigrationStatusService migrationStatusService,
ISyncMigrationPackService packService,
IHubContext<SyncHub> hubContext)
{
_migrationService = migrationService;
_profileConfigService = profileConfigService;
Expand All @@ -58,11 +67,40 @@ public uSyncMigrationsController(
_migrationFileService = migrationFileService;
_shortStringHelper = shortStringHelper;
_migrationStatusService = migrationStatusService;
_packService = packService;
_hubContext = hubContext;
}

[HttpGet]
public bool GetApi() => true;

[HttpPost]
[Authorize(Roles = UmbConstants.Security.AdminGroupAlias)]
public ActionResult Download(string clientId)
{
var client = new HubClientService(_hubContext, clientId);


client?.Callbacks().Update.Invoke("Downloading ", 0, 10);

var id = Guid.NewGuid();
var result = _packService.CreateSitePack(id, client?.Callbacks());


client?.Callbacks().Callback.Invoke(
new SyncProgressSummary(Enumerable.Empty<SyncHandlerSummary>(), "Zipping package", 1));

client?.Callbacks().Update.Invoke("Zipping", 1, 1);

var stream = _packService.ZipPack(result);

return new FileStreamResult(stream, MediaTypeNames.Application.Zip)
{
FileDownloadName = $"migrationPack_{DateTime.Now:yyyyMMdd_HHmmss}.zip"
};

}


[HttpPost]
[Authorize(Roles = UmbConstants.Security.AdminGroupAlias)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@
<key alias="startIntro">Convert some files, import them into umbraco</key>

<key alias="selectSource">Select source</key>
<key alias="selectSource-desc">Select a folder on disk containing the data you want to migrate</key>

<key alias="uploadZip">Upload a zip</key>
<key alias="uploadZip-desc">Select a zip file containing the uSync and config files for the migration</key>

<key alias="convertTitle">Convert this site</key>
<key alias="convertIntro">Convert the properties on this site</key>
<key alias="convertIntro">Convert the properties on this site in place</key>
<key alias="convert">Convert</key>
<key alias="convert-desc">Convert the settings and content of this site. (don't do this on a production site!)</key>

<key alias="download">Download</key>
<key alias="download-desc">Download the contents of this site for conversion on another umbraco install</key>

<key alias="download-intro"><![CDATA[
<p>Create a zip of the settings and content for this site.</p>
<p>The zip file will contain...</p>
]]></key>

<key alias="convertedLabel">Files converted</key>
<key alias="convertedDesc">Have the files been converted</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

vm.pickSource = pickSource;
vm.uploadZip = uploadZip;
vm.download = download;
vm.edit = edit;

vm.canBeImported = canBeImported;
Expand Down Expand Up @@ -88,6 +89,19 @@
});
}

function download() {
editorService.open({
title: 'download',
size: 'small',
view: Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath + '/uSyncMigrations/dialogs/download.html',
hub: vm.hub,
close: function () {
editorService.close();
}
});
}


function validate(status) {
vm.validating = true;
uSyncMigrationService.validate(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,34 @@
<h2><localize key="usyncmigrate_startTitle"></localize></h2>
</div>
</div>
<div>
<div class="mb4 mt3">
<localize key="usyncmigrate_startIntro"></localize>
</div>
<div class="usync-group-buttons">
<umb-button button-style="success"
icon="icon-folder"
action="vm.pickSource()"
size="l"
label-key="usyncmigrate_selectSource">
</umb-button>

<umb-button button-style="success"
icon="icon-zip"
action="vm.uploadZip()"
size="l"
label-key="usyncmigrate_uploadZip">
</umb-button>
<div class="usync-migration-buttons">
<div class="usync-migration-button">
<umb-button button-style="success block"
icon="icon-folder"
action="vm.pickSource()"
size="l"
label-key="usyncmigrate_selectSource">
</umb-button>

<div class="usync-migration-button-desc">
<localize key="usyncmigrate_selectSource-desc"></localize>
</div>
</div>

<div class="usync-migration-button">
<umb-button button-style="success block"
icon="icon-zip"
action="vm.uploadZip()"
size="l"
label-key="usyncmigrate_uploadZip">
</umb-button>
<div class="usync-migration-button-desc">
<localize key="usyncmigrate_uploadZip-desc"></localize>
</div>
</div>
</div>
</umb-box-content>
</umb-box>
Expand All @@ -59,13 +70,30 @@ <h2><localize key="usyncmigrate_startTitle"></localize></h2>
<h2><localize key="usyncmigrate_convertTitle"></localize></h2>
</div>
</div>
<div><localize key="usyncmigrate_convertIntro"></localize></div>
<div class="usync-group-buttons">
<umb-button button-style="success btn-large"
action="vm.existing();"
icon="icon-nodes"
label-key="usyncmigrate_convert">
</umb-button>
<div class="mb4 mt3"><localize key="usyncmigrate_convertIntro"></localize></div>
<div class="usync-migration-buttons">
<div class="usync-migration-button">
<umb-button button-style="success block"
action="vm.existing();"
icon="icon-nodes"
size="l"
label-key="usyncmigrate_convert">
</umb-button>
<div class="usync-migration-button-desc">
<localize key="usyncmigrate_convert-desc"></localize>
</div>
</div>
<div class="usync-migration-button">
<umb-button button-style="action block"
action="vm.download();"
icon="icon-download"
size="l"
label-key="usyncmigrate_download">
</umb-button>
<div class="usync-migration-button-desc">
<localize key="usyncmigrate_download-desc"></localize>
</div>
</div>
</div>
</umb-box-content>
</umb-box>
Expand Down Expand Up @@ -145,7 +173,7 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>
<umb-box>
<umb-box-content>
<div class="text-center">
Validation in progress....<br/>
Validation in progress....<br />
(For big sites this can take a while)
</div>
</umb-box-content>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
(function () {
'use strict';

function downloadController($scope,
notificationsService,
uSyncMigrationService) {

var vm = this;
vm.working = false;
vm.download = download;

vm.status = {};
vm.update = {};

vm.$onInit = function () {
vm.hub = $scope.model.hub;

vm.hub.on('update', function (update) {
console.log('update', update);
vm.update = update;
});

vm.hub.on('add', function (add) {
console.log('add', add);
vm.status = add;
});
}

function getClientId() {
if ($.connection !== undefined) {
return $.connection.connectionId;
}
return "";
}

vm.close = function () {
$scope.model.close();
}

function download() {

vm.working = true;

uSyncMigrationService.download(getClientId())
.then(function () {
vm.working = false;
console.log('done');
vm.close();
}, function (error) {
notificationsService.error('failed', 'failed to download, check console');
console.log(error);
});
}
}

angular.module('umbraco')
.controller('uSyncDownloadMigrationController', downloadController)
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<div ng-controller="uSyncDownloadMigrationController as vm">
<umb-editor-panel>
<umb-editor-header name="'download'"
description="'download the setup of this site'"
name-locked="true"
description-locked="true"
hide-alias="true"
hide-icon="true"></umb-editor-header>

<umb-editor-container class="form-horizontal">

<umb-box>
<umb-box-header title="Download"></umb-box-header>
<umb-box-content>
<localize key="usyncmigrate_download-intro"></localize>
</umb-box-content>

<umb-box-content ng-if="!vm.working">
<div class="flex justify-center">

<umb-button type="button"
button-style="success"
size="l"
label-key="usyncmigrate_download"
action="vm.download()"></umb-button>

</div>
</umb-box-content>
</umb-box>

<umb-box ng-if="vm.working">
<umb-box-content class="flex justify-center flex-column items-stretch">

<div>
<div class="text-center">
<div>
<strong>{{vm.status.message}}</strong>
</div>
<em>({{vm.status.count}} / {{vm.status.total}})</em>
</div>
</div>
<div class="text-center">
<div style="margin-top: 20px; height: 50px;">
{{vm.update.message}}
</div>
<umb-progress-bar percentage="{{vm.update.percentage}}"
size="m"
color="primary"></umb-progress-bar>
<div>
<em>{{vm.update.count}}/{{vm.update.total}}</em>
</div>
</div>
</umb-box-content>

</umb-box>

</umb-editor-container>

<umb-editor-footer>
<umb-editor-footer-content-right>

<umb-button type="button"
button-style="link"
label-key="general_close"
action="vm.close()"></umb-button>

</umb-editor-footer-content-right>
</umb-editor-footer>
</umb-editor-panel>
</div>
Loading

0 comments on commit 927c877

Please sign in to comment.