Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"datatables.net": "^2.3.2",
"datatables.net-bs5": "^2.3.2",
"dattatable": "^2.11.62",
"gd-sprest-bs": "^10.15.31",
"gd-sprest-bs": "^10.15.35",
"jquery": "^3.7.1",
"moment": "^2.30.1"
},
Expand Down
2 changes: 1 addition & 1 deletion spfx/config/package-solution.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"solution": {
"name": "site-admin-tool",
"id": "9c7bcdac-024d-4ffe-b63a-cef526bc1930",
"version": "0.9.7.9",
"version": "0.9.8.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false,
Expand Down
150 changes: 66 additions & 84 deletions src/reports/sensitivityLabels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Dashboard, DataTable, Documents, LoadingDialog, Modal } from "dattatable";
import { Dashboard, Documents, LoadingDialog, Modal } from "dattatable";
import { Components, Helper, SPTypes, Types, Web, v2 } from "gd-sprest-bs";
import { fileEarmarkText } from "gd-sprest-bs/build/icons/svgs/fileEarmarkText";
import { DataSource } from "../ds";
Expand Down Expand Up @@ -236,106 +236,91 @@ export class SensitivityLabels {
let responses: ISetSensitivityLabelResponse[] = [];

// Show the responses
this.showResponses(responses);
this.showResponses(responses, () => {
// Stop the worker process
worker.stop();
});

// Update the dialog
this._elSubNav.children[0].innerHTML = `Loading files from library: ${listName}`;

// Process the labels as we load the files
let fileCounter = 0;
let filesToProcess: Types.Microsoft.Graph.driveItem[] = [];
let isRunning = false;
let onCompleted = null;
let isProcessing = false;
let processedCounter = 0;
let startProcess = (callback?: () => void): PromiseLike<void> => {
// Set the callback method
onCompleted = callback || onCompleted;

// Do nothing if we are already running
if (isRunning) { return; }
// Create a worker process
let worker = Helper.WebWorker(() => {
// Do nothing if we are processing an item
if (isProcessing) { return; }

// Set the flags
let isProcessing = false;
isRunning = true;
// Do nothing if we are done
if (filesToProcess.length == 0) {
// Stop the process
worker.stop();

// Loop while there are files to process
let loopIdx = setInterval(() => {
// Do nothing if we are processing an item
if (isProcessing) { return; }
// Call the event
onCompleted ? onCompleted() : null;

// Do nothing if we are done
if (filesToProcess.length == 0) {
// Stop the loop
clearInterval(loopIdx);
// Do nothing
return;
}

// Set the flag
isRunning = false;
// Get the file to process
let file = filesToProcess.splice(0, 1)[0];

// Call the event
onCompleted ? onCompleted() : null;
}
// See if the file extensions are provided
if (fileExtensions && fileExtensions.length > 0) {
let analyzeFile = false

// Get the file to process
let file = filesToProcess.splice(0, 1)[0];
// Loop through the file extensions
fileExtensions.forEach(fileExt => {
// Set the flag if there is match
if (file.name?.toLowerCase().endsWith(fileExt.toLowerCase())) { analyzeFile = true; }
});

// See if the file extensions are provided
if (fileExtensions && fileExtensions.length > 0) {
let analyzeFile = false
// See if we are not analyzing the file
if (!analyzeFile) {
// Add a response
let response: ISetSensitivityLabelResponse = {
errorFl: false,
fileName: file.name,
message: `Skipping file, file extension not listed to process.`,
url: file.webUrl
};
responses.push(response);
this._dashboard.Datatable.addRow(response);

// Loop through the file extensions
fileExtensions.forEach(fileExt => {
// Set the flag if there is match
if (file.name?.toLowerCase().endsWith(fileExt.toLowerCase())) { analyzeFile = true; }
});
// Update the dialog
this._elSubNav.children[1].innerHTML = `[Processed ${++processedCounter} of ${fileCounter}] ${response.message}`;

// See if we are not analyzing the file
if (!analyzeFile) {
// Add a response
let response: ISetSensitivityLabelResponse = {
errorFl: false,
fileName: file.name,
message: `Skipping file, file extension not listed to process.`,
url: file.webUrl
};
responses.push(response);
this._dashboard.Datatable.addRow(response);
// Check the next file
return;
}
}

// Update the dialog
this._elSubNav.children[1].innerHTML = `[Processed ${++processedCounter} of ${fileCounter}] ${response.message}`;
// Set the flag
isProcessing = true;

// Check the next file
return;
}
}
// Update the dialog
this._elSubNav.children[1].innerHTML = `[Processing ${processedCounter} of ${fileCounter}] Labelling File: ${file.name}`;

// Label the file
this.labelFile(file, overrideLabelFl, label.text, label.value, justification, responses).then(() => {
// Set the flag
isProcessing = true;
isProcessing = false;

// Update the dialog
this._elSubNav.children[1].innerHTML = `[Processed ${processedCounter} of ${fileCounter}] Labelling File: ${file.name}`;

// Label the file
this.labelFile(file, overrideLabelFl, label.text, label.value, justification, responses).then(() => {
// Set the flag
isProcessing = false;

// Update the dialog
this._elSubNav.children[1].innerHTML = `[Processed ${++processedCounter} of ${fileCounter}] File Labelled: ${file.name}`;

// See if we are done
if (filesToProcess.length == 0) {
// Stop the loop
clearInterval(loopIdx);

// Set the flag
isRunning = false;
this._elSubNav.children[1].innerHTML = `[Processed ${++processedCounter} of ${fileCounter}] File Labelled: ${file.name}`;
});
}, 100);

// Call the event
onCompleted ? onCompleted() : null;
}
});
}, 10);
}
// Set the completed event
let onCompleted = () => {
// Clear the sub-nav
this._elSubNav.classList.add("d-none");
};

// Load the files for this drive
DataSource.loadFiles(webId, listName, folder, file => {
Expand All @@ -346,13 +331,7 @@ export class SensitivityLabels {
this._elSubNav.children[0].innerHTML = `Loading files from library: ${listName} [Files Loaded: ${++fileCounter}]`;

// Ensure the process is running
startProcess();
}).then(() => {
// Ensure the process is running
startProcess(() => {
// Clear the sub-nav
this._elSubNav.classList.add("d-none");
});
worker.start();
});
}

Expand Down Expand Up @@ -831,12 +810,15 @@ export class SensitivityLabels {
}

// Shows the responses for setting the sensitivity labels
private static showResponses(responses: ISetSensitivityLabelResponse[]) {
private static showResponses(responses: ISetSensitivityLabelResponse[], onClose?: () => void) {
// Clear the modal and set the header
Modal.clear();
Modal.setType(Components.ModalTypes.Full);
Modal.setHeader("Set Sensitivity Label Results");

// Set the close event
Modal.setCloseEvent(onClose);

// Set the dashboard
this._dashboard = new Dashboard({
el: Modal.BodyElement,
Expand Down