Skip to content

Commit

Permalink
Export overlay html
Browse files Browse the repository at this point in the history
  • Loading branch information
ninalemmens committed Jan 10, 2023
1 parent a253550 commit 7748570
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
angular.module('umbraco').controller('SimpleRedirects.ImportExportController', function ($scope, Upload, editorService, notificationsService) {
const vm = this;

vm.loading = true;
vm.buttonStates = 'init';
vm.importing = false;
vm.file = null;
vm.overwriteMatches = false;
vm.importResponse = null;
vm.importErrorList = [];
vm.importErrorListPageResult = [];
vm.importErrorListResultsPerPage = 5;
vm.redirectTotal = $scope.model.value.redirects;

vm.pagination = {
pageNumber: 1,
totalPages: 1
};

vm.nextPage = nextPage;
vm.prevPage = prevPage;
vm.changePage = changePage;
vm.goToPage = goToPage;

function nextPage(pageNumber) {
changePage(pageNumber);
}

function prevPage(pageNumber) {
changePage(pageNumber);
}

function changePage(pageNumber) {
if (pageNumber <= vm.pagination.totalPages && pageNumber > 0) {
vm.importErrorListPageResult = vm.importErrorList.slice((pageNumber - 1) * vm.importErrorListResultsPerPage, pageNumber * vm.importErrorListResultsPerPage);
vm.pagination.pageNumber = pageNumber;
}
}

function goToPage(pageNumber) {
changePage(pageNumber)
}

vm.exportFileName = {
text: '',
regex: '/[^a-z0-9_\\-]/gi',
placeholder: 'Optionally type a filename'
}

vm.import = function importRedirects() {
if (vm.file !== null) {
toggleLoading();
Upload.upload({
url: "backoffice/SimpleRedirects/RedirectApi/ImportRedirects?overwriteMatches=" + vm.overwriteMatches,
file: vm.file
}).then(function (response) {
if (!response || !response.data || response.status !== 200) {
notificationsService.error("Import failed", "An error occured while importing provided import list");
} else {
notificationsService.success("Import completed", "Successfully ran through all import rows in provided file");
vm.importResponse = response.data;
vm.redirectTotal = vm.redirectTotal + vm.importResponse.addedRedirects;
vm.importErrorList = [];
if (vm.importResponse.errorRedirects.length > 0) {
for (let i = 0; i < vm.importResponse.errorRedirects.length; i++) {
const errorIndex = vm.importResponse.errorRedirects[i];
const error = {
entry: i + 1,
message: errorIndex.notes,
oldUrl: errorIndex.oldUrl,
newUrl: errorIndex.newUrl,
redirectCode: errorIndex.redirectCode,
}
vm.importErrorList.push(error);
}
UpdatePagination();
}
}
toggleLoading();
});
}
}

function UpdatePagination() {
vm.pagination.pageNumber = 1;
vm.pagination.totalPages = Math.ceil(vm.importErrorList.length / vm.importErrorListResultsPerPage);
vm.goToPage(1);
}

vm.buttonGroup = {
defaultButton: {
labelKey: "actions_exportToCsv",
handler: function () {
if (!vm.loading) {
toggleLoading();
location.href = "/umbraco/backoffice/SimpleRedirects/RedirectApi/ExportRedirects?dataRecordProvider=Csv";
toggleLoading();
}
}
},
subButtons: [
{
labelKey: "actions_exportToExcel",
handler: function () {
if (!vm.loading) {
toggleLoading();
location.href = "/umbraco/backoffice/SimpleRedirects/RedirectApi/ExportRedirects?dataRecordProvider=Excel";
toggleLoading();
}
}
}
]
};

vm.toggleOverwriteMatches = function () {
vm.overwriteMatches = !vm.overwriteMatches;
}

$scope.handleFile = function ($file) {
vm.file = $file;
};

function toggleLoading() {
vm.loading = !vm.loading;
vm.buttonStates = vm.loading ? "busy" : "success";
}


function init() {
toggleLoading();
}

init();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="redirects-export-import" ng-controller="SimpleRedirects.ImportExportController as vm" noDirtyCheck>
<span>{{ vm.redirectTotal }} records available for export.</span>
<umb-button-group
class="button-right"
ng-if="vm.buttonGroup"
default-button="vm.buttonGroup.defaultButton"
sub-buttons="vm.buttonGroup.subButtons"
button-style="primary"
icon="icon-download-alt"
direction="down"
disabled="vm.redirectTotal === 0"
state="vm.buttonStates"
float="right">
</umb-button-group>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
angular.module('umbraco').controller('SimpleRedirects.ImportExportController', function ($scope, Upload, editorService, notificationsService) {
const vm = this;

vm.loading = true;
vm.buttonStates = 'init';
vm.importing = false;
vm.file = null;
vm.overwriteMatches = false;
vm.importResponse = null;
vm.importErrorList = [];
vm.importErrorListPageResult = [];
vm.importErrorListResultsPerPage = 5;
vm.redirectTotal = $scope.model.value.redirects;

vm.pagination = {
pageNumber: 1,
totalPages: 1
};

vm.nextPage = nextPage;
vm.prevPage = prevPage;
vm.changePage = changePage;
vm.goToPage = goToPage;

function nextPage(pageNumber) {
changePage(pageNumber);
}

function prevPage(pageNumber) {
changePage(pageNumber);
}

function changePage(pageNumber) {
if (pageNumber <= vm.pagination.totalPages && pageNumber > 0) {
vm.importErrorListPageResult = vm.importErrorList.slice((pageNumber - 1) * vm.importErrorListResultsPerPage, pageNumber * vm.importErrorListResultsPerPage);
vm.pagination.pageNumber = pageNumber;
}
}

function goToPage(pageNumber) {
changePage(pageNumber)
}

vm.exportFileName = {
text: '',
regex: '/[^a-z0-9_\\-]/gi',
placeholder: 'Optionally type a filename'
}

vm.import = function importRedirects() {
if (vm.file !== null) {
toggleLoading();
Upload.upload({
url: "backoffice/SimpleRedirects/RedirectApi/ImportRedirects?overwriteMatches=" + vm.overwriteMatches,
file: vm.file
}).then(function (response) {
if (!response || !response.data || response.status !== 200) {
notificationsService.error("Import failed", "An error occured while importing provided import list");
} else {
notificationsService.success("Import completed", "Successfully ran through all import rows in provided file");
vm.importResponse = response.data;
vm.redirectTotal = vm.redirectTotal + vm.importResponse.addedRedirects;
vm.importErrorList = [];
if (vm.importResponse.errorRedirects.length > 0) {
for (let i = 0; i < vm.importResponse.errorRedirects.length; i++) {
const errorIndex = vm.importResponse.errorRedirects[i];
const error = {
entry: i + 1,
message: errorIndex.notes,
oldUrl: errorIndex.oldUrl,
newUrl: errorIndex.newUrl,
redirectCode: errorIndex.redirectCode,
}
vm.importErrorList.push(error);
}
UpdatePagination();
}
}
toggleLoading();
});
}
}

function UpdatePagination() {
vm.pagination.pageNumber = 1;
vm.pagination.totalPages = Math.ceil(vm.importErrorList.length / vm.importErrorListResultsPerPage);
vm.goToPage(1);
}

vm.buttonGroup = {
defaultButton: {
labelKey: "actions_exportToCsv",
handler: function () {
if (!vm.loading) {
toggleLoading();
location.href = "/umbraco/backoffice/SimpleRedirects/RedirectApi/ExportRedirects?dataRecordProvider=Csv";
toggleLoading();
}
}
},
subButtons: [
{
labelKey: "actions_exportToExcel",
handler: function () {
if (!vm.loading) {
toggleLoading();
location.href = "/umbraco/backoffice/SimpleRedirects/RedirectApi/ExportRedirects?dataRecordProvider=Excel";
toggleLoading();
}
}
}
]
};

vm.toggleOverwriteMatches = function () {
vm.overwriteMatches = !vm.overwriteMatches;
}

$scope.handleFile = function ($file) {
vm.file = $file;
};

function toggleLoading() {
vm.loading = !vm.loading;
vm.buttonStates = vm.loading ? "busy" : "success";
}


function init() {
toggleLoading();
}

init();
});
14 changes: 14 additions & 0 deletions source/SimpleRedirects/App_Plugins/SimpleRedirects/export.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="redirects-export-import" ng-controller="SimpleRedirects.ImportExportController as vm" noDirtyCheck>
<span>{{ vm.redirectTotal }} records available for export.</span>
<umb-button-group
ng-if="vm.buttonGroup"
default-button="vm.buttonGroup.defaultButton"
sub-buttons="vm.buttonGroup.subButtons"
button-style="primary"
icon="icon-download-alt"
direction="down"
disabled="vm.redirectTotal === 0"
state="vm.buttonStates"
float="right">
</umb-button-group>
</div>

0 comments on commit 7748570

Please sign in to comment.