Skip to content

Commit

Permalink
fix filemanager controller issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanhashmey committed Feb 1, 2024
1 parent 4cb15e4 commit 38ebc72
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 126 deletions.
264 changes: 138 additions & 126 deletions filemanager/static/filemanager/js/fileManagerV2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
newapp.controller('fileManagerCtrlV2', function ($scope, $http, FileUploader, $window) {

alert('Error');

$('form').submit(function (e) {
e.preventDefault();
});
Expand Down Expand Up @@ -446,10 +446,142 @@ newapp.controller('fileManagerCtrlV2', function ($scope, $http, FileUploader, $w
}


// Button Activator



$scope.fetchForTableSecondary = function (node, functionName) {


console.log("habbi.................run");

allFilesAndFolders = [];
$scope.buttonActivator();
url = "/filemanager/controller";
var completePathToFile = "";

if (domainName === "") {

if (functionName === "startPoint") {
completePathToFile = $scope.currentRPath;
} else if (functionName === "doubleClick") {
completePathToFile = $scope.currentRPath + "/" + node.innerHTML;
} else if (functionName === "homeFetch") {
completePathToFile = homeRPathBack;
} else if (functionName === "goBackOnPath") {
var pos = $scope.currentRPath.lastIndexOf("/");
completePathToFile = $scope.currentRPath.slice(0, pos);
} else if (functionName === "refresh") {
completePathToFile = $scope.currentRPath;
var rightClickNode = document.getElementById("rightClick");
} else if (functionName === "fromTree") {
completePathToFile = arguments[2];
}
$scope.currentRPath = completePathToFile;

} else {
if (functionName === "startPoint") {
completePathToFile = $scope.currentPath;
// check if there is any path in QS

const urlParams = new URLSearchParams(window.location.search);
QSPath = urlParams.get('path')

if (QSPath !== null) {
completePathToFile = QSPath
}

//
} else if (functionName === "doubleClick") {
completePathToFile = $scope.currentPath + "/" + node.innerHTML;
} else if (functionName === "homeFetch") {
completePathToFile = homePathBack;
} else if (functionName === "goBackOnPath") {
var pos = $scope.currentPath.lastIndexOf("/");
completePathToFile = $scope.currentPath.slice(0, pos);
} else if (functionName === "refresh") {
completePathToFile = $scope.currentPath;
var rightClickNode = document.getElementById("rightClick");
} else if (functionName === "fromTree") {
completePathToFile = arguments[2];
}
$scope.currentPath = completePathToFile;
}


var data = {
completeStartingPath: completePathToFile,
method: "listForTable",
home: "/",
domainRandomSeed: domainRandomSeed,
domainName: domainName
};

var tableBody = document.getElementById("tableBodyFiles");
var loadingPath = "/static/filemanager/images/loading.gif";
tableBody.innerHTML = '<img src="' + loadingPath + '">';


var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};


$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);

function ListInitialDatas(response) {

tableBody.innerHTML = '';


if (response.data.status === 1) {


/// node prepration

var filesData = response.data;

var keys = Object.keys(filesData);

for (var i = 0; i < keys.length; i++) {
if (keys[i] === "error_message" | keys[i] === "status") {
continue;
} else {
var fileName = filesData[keys[i]][0];
var lastModified = filesData[keys[i]][2];
var fileSize = filesData[keys[i]][3];
var permissions = filesData[keys[i]][4];
var dirCheck = filesData[keys[i]][5];
// console.log(fileName);
if (fileName === "..filemanagerkey") {

continue;
}
tableBody.appendChild(createTR(fileName, fileSize, lastModified, permissions, dirCheck));

}
}
} else {
var notification = alertify.notify(response.data.error_message, 'error', 10, function () {
});
$scope.fetchForTableSecondary(null, 'homeFetch');
}

}

function cantLoadInitialDatas(response) {
}

};


// Button Activator

$scope.buttonActivator = function () {

console.log("----------cal button activater------------");

// for restore button
if ($scope.currentPath === trashPath) {
var restoreBTN = document.getElementById("restoreRight");
Expand All @@ -458,6 +590,10 @@ newapp.controller('fileManagerCtrlV2', function ($scope, $http, FileUploader, $w
var restoreBTN = document.getElementById("restoreRight");
restoreBTN.style.display = "none";
}

console.log("----------cal button activater-----------1-");


// for edit button

if (allFilesAndFolders.length === 1) {
Expand Down Expand Up @@ -599,130 +735,6 @@ newapp.controller('fileManagerCtrlV2', function ($scope, $http, FileUploader, $w

// table functions


$scope.fetchForTableSecondary = function (node, functionName) {

allFilesAndFolders = [];
$scope.buttonActivator();
url = "/filemanager/controller";
var completePathToFile = "";

if (domainName === "") {

if (functionName === "startPoint") {
completePathToFile = $scope.currentRPath;
} else if (functionName === "doubleClick") {
completePathToFile = $scope.currentRPath + "/" + node.innerHTML;
} else if (functionName === "homeFetch") {
completePathToFile = homeRPathBack;
} else if (functionName === "goBackOnPath") {
var pos = $scope.currentRPath.lastIndexOf("/");
completePathToFile = $scope.currentRPath.slice(0, pos);
} else if (functionName === "refresh") {
completePathToFile = $scope.currentRPath;
var rightClickNode = document.getElementById("rightClick");
} else if (functionName === "fromTree") {
completePathToFile = arguments[2];
}
$scope.currentRPath = completePathToFile;

} else {
if (functionName === "startPoint") {
completePathToFile = $scope.currentPath;
// check if there is any path in QS

const urlParams = new URLSearchParams(window.location.search);
QSPath = urlParams.get('path')

if (QSPath !== null) {
completePathToFile = QSPath
}

//
} else if (functionName === "doubleClick") {
completePathToFile = $scope.currentPath + "/" + node.innerHTML;
} else if (functionName === "homeFetch") {
completePathToFile = homePathBack;
} else if (functionName === "goBackOnPath") {
var pos = $scope.currentPath.lastIndexOf("/");
completePathToFile = $scope.currentPath.slice(0, pos);
} else if (functionName === "refresh") {
completePathToFile = $scope.currentPath;
var rightClickNode = document.getElementById("rightClick");
} else if (functionName === "fromTree") {
completePathToFile = arguments[2];
}
$scope.currentPath = completePathToFile;
}


var data = {
completeStartingPath: completePathToFile,
method: "listForTable",
home: "/",
domainRandomSeed: domainRandomSeed,
domainName: domainName
};

var tableBody = document.getElementById("tableBodyFiles");
var loadingPath = "/static/filemanager/images/loading.gif";
tableBody.innerHTML = '<img src="' + loadingPath + '">';


var config = {
headers: {
'X-CSRFToken': getCookie('csrftoken')
}
};


$http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas);

function ListInitialDatas(response) {

tableBody.innerHTML = '';


if (response.data.status === 1) {


/// node prepration

var filesData = response.data;

var keys = Object.keys(filesData);

for (var i = 0; i < keys.length; i++) {
if (keys[i] === "error_message" | keys[i] === "status") {
continue;
} else {
var fileName = filesData[keys[i]][0];
var lastModified = filesData[keys[i]][2];
var fileSize = filesData[keys[i]][3];
var permissions = filesData[keys[i]][4];
var dirCheck = filesData[keys[i]][5];
// console.log(fileName);
if (fileName === "..filemanagerkey") {

continue;
}
tableBody.appendChild(createTR(fileName, fileSize, lastModified, permissions, dirCheck));

}
}
} else {
var notification = alertify.notify(response.data.error_message, 'error', 10, function () {
});
$scope.fetchForTableSecondary(null, 'homeFetch');
}

}

function cantLoadInitialDatas(response) {
}

};

function findFileExtension(fileName) {
return (/[.]/.exec(fileName)) ? /[^.]+$/.exec(fileName) : undefined;
}
Expand Down
64 changes: 64 additions & 0 deletions filemanager/templates/filemanager/indexv2.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
{# </head>#}

<div ng-controller="fileManagerCtrlV2" class="p-8">

<span style="display: none" id="domainNameInitial">{{ domainName }}</span>

<div class="flex py-2 px-6 items-center gap-4">
<div>
<p class="font-bold w-32">Current Path</p>
Expand Down Expand Up @@ -691,6 +694,9 @@ <h4 class="font-bold mt-4">{% trans "Drop" %}</h4>
<table class="w-full text-sm text-left rtl:text-right">
<thead id="tableHead">
<tr>
<th scope="col" class="px-6 py-3">

</th>
<th scope="col" class="px-6 py-3">
File Name
</th>
Expand All @@ -711,5 +717,63 @@ <h4 class="font-bold mt-4">{% trans "Drop" %}</h4>
</div>
</div>
</div>

<div style="position: absolute;top: 0;left: 0;" id="rightClick" class="card" style="width: 20rem;">
<ul class="list-group list-group-flush">
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showMoveModal()"
href="#">
<li class="list-group-item"><i class="fa fa-arrows-alt" aria-hidden="true"></i> {% trans "Move" %}
</li>
</a>
<a style="border-bottom: 1px solid #007bff;" id="downloadOnRight" onclick="return false;"
ng-click="downloadFile()" href="#">
<li class="list-group-item"><i class="fa fa-download" aria-hidden="true"></i> {% trans "Download" %}
</li>
</a>
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showCopyModal()"
href="#">
<li class="list-group-item"><i class="fa fa-files-o" aria-hidden="true"></i> {% trans "Copy" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showRenameModal()"
href="#">
<li class="list-group-item"><i class="fa fa-file-text-o"
aria-hidden="true"></i> {% trans "Rename" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showPermissionsModal()"
href="#">
<li class="list-group-item"><i class="fa fa-lock"
aria-hidden="true"></i> {% trans "Change Permissions" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showDeleteModal()"
href="#">
<li class="list-group-item"><i class="fa fa-trash" aria-hidden="true"></i> {% trans "Delete" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" onclick="return false;" ng-click="showCompressionModal()"
href="#">
<li class="list-group-item"><i class="fa fa-compress" aria-hidden="true"></i> {% trans "Compress" %}
</li>
</a>
<a style="border-bottom: 1px solid #007bff;" id="extractOnRight" onclick="return false;"
ng-click="showExtractionModal()" href="#">
<li class="list-group-item"><i class="fa fa-expand" aria-hidden="true"></i> {% trans "Extract" %}
</li>
</a>
<a style="border-bottom: 1px solid #007bff;" id="editOnRight" onclick="return false;"
ng-click="showHTMLEditorModal(1)" href="#">
<li class="list-group-item"><i class="fa fa-pencil-square-o"
aria-hidden="true"></i> {% trans "Edit" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" id="editOnRightCodeMirror" onclick="return false;"
ng-click="editWithCodeMirror()" href="#">
<li class="list-group-item"><i class="fa fa-pencil-square-o"
aria-hidden="true"></i> {% trans "Edit with CodeMirror" %}</li>
</a>
<a style="border-bottom: 1px solid #007bff;" id="restoreRight" onclick="return false;"
ng-click="showRestoreModal()" href="#">
<li class="list-group-item"><i class="fa fa-window-restore"
aria-hidden="true"></i> {% trans "Restore" %}</li>
</a>
</ul>
</div>
</div>
{% endblock %}

0 comments on commit 38ebc72

Please sign in to comment.