-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implement file manager, part 2
- Loading branch information
Showing
11 changed files
with
151 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
ckan.module("fm-htmx", function ($) { | ||
return { | ||
options: { | ||
formId: null, | ||
}, | ||
initialize: function () { | ||
$.proxyAll(this, /_on/); | ||
|
||
document.addEventListener('htmx:beforeRequest', this._onHTMXbeforeRequest); | ||
document.addEventListener('htmx:afterSettle', this._onHTMXafterSettle); | ||
document.addEventListener('htmx:confirm', this._onHTMXconfirm); | ||
document.addEventListener('htmx:afterRequest', this._onAfterRequest) | ||
}, | ||
|
||
_onHTMXbeforeRequest: function (e) { | ||
$(e.detail.target).find("[data-module]").unbind() | ||
|
||
for (const [key, _] of Object.entries(ckan.module.instances)) { | ||
ckan.module.instances[key] = null; | ||
} | ||
}, | ||
|
||
_onHTMXafterSettle: function (e) { | ||
const doNotInitialize = ["ap-hyperscript"] | ||
|
||
$(e.detail.target).find("[data-module]").each(function (_, element) { | ||
const moduleName = $(element).attr("data-module"); | ||
|
||
if (!doNotInitialize.includes(moduleName)) { | ||
ckan.module.initializeElement(element); | ||
} | ||
}) | ||
}, | ||
|
||
_onHTMXconfirm: function (evt) { | ||
if (evt.detail.path.includes("/file_manager/delete")) { | ||
evt.preventDefault(); | ||
|
||
swal({ | ||
text: this._("Are you sure you wish to delete a file?"), | ||
icon: "warning", | ||
buttons: true, | ||
dangerMode: true, | ||
}).then((confirmed) => { | ||
if (confirmed) { | ||
evt.detail.issueRequest(); | ||
this.sandbox.publish("ap:notify", this._("A file has been removed")); | ||
} | ||
}); | ||
} | ||
}, | ||
|
||
_onAfterRequest: function (evt) { | ||
if (evt.detail.pathInfo.requestPath.includes("/file_manager/delete/")) { | ||
htmx.trigger(`#${this.options.formId}`, "change"); | ||
} | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
file-manager-js: | ||
filter: rjsmin | ||
output: ckanext-admin_panel/%(version)s-file-manager.js | ||
contents: | ||
- js/fm-htmx.js | ||
extra: | ||
preload: | ||
- base/main | ||
- base/ckan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from __future__ import annotations | ||
|
||
from datetime import datetime | ||
|
||
import ckan.plugins.toolkit as tk | ||
|
||
from ckanext.toolbelt.decorators import Collector | ||
|
||
import ckanext.ap_main.types as ap_types | ||
|
||
renderer, get_renderers = Collector("fm").split() | ||
|
||
|
||
@renderer | ||
def last_access( | ||
rows: ap_types.ItemList, | ||
row: ap_types.Item, | ||
value: ap_types.ItemValue, | ||
**kwargs, | ||
) -> int: | ||
if not value: | ||
return tk._("Never") | ||
|
||
datetime_obj = datetime.fromisoformat(value) | ||
current_date = datetime.now() | ||
|
||
days_passed = (current_date - datetime_obj).days | ||
|
||
return days_passed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import ckanext.files.config as files_conf | ||
|
||
|
||
def files_get_unused_threshold() -> int: | ||
return files_conf.get_unused_threshold() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters