Skip to content

Commit

Permalink
@wip new single page viewer, new share function, fixxed some style is…
Browse files Browse the repository at this point in the history
…sue, etc..
  • Loading branch information
cian authored and cian committed Mar 2, 2023
1 parent 4e5b2b0 commit 28b9909
Show file tree
Hide file tree
Showing 31 changed files with 360 additions and 219 deletions.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="/icon-scriptor.ico" />

<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Scriptor v1.0</title>
</head>
<body>
Expand Down
Binary file added public/icon-scriptor.ico
Binary file not shown.
18 changes: 15 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default {
setup(){
const checkLoginInterval = ref();
const globalStore = useGlobalStore();
let isLoggedIn = ref<boolean>(false);
let isLoading = ref<boolean>(true);
Expand All @@ -60,21 +62,31 @@ export default {
isLoading.value = false;
}
onBeforeMount(async () => {
try {
async function checkLogin(allowInit = false) {
try {
let resp = await Request.get("/vi/user/view/self");
let data = await resp.json();
isLoggedIn.value = true;
global.user = data.values;
await init();
if (allowInit)
await init();
//messageStore.addMessage("debug", "Text-Nachricht", "Ich bin ein Text");
}
catch (error) {
isLoggedIn.value = false;
messageStore.addMessage("error", t("error.title.login"), t("error.text.login"));
}
}
onBeforeMount(async () => {
await checkLogin(true);
setInterval(async () => {
await checkLogin();
}, 1000 * 60 * 5)
});
return {isLoggedIn, isLoading, globalStore}
Expand Down
13 changes: 11 additions & 2 deletions src/assets/scriptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class prototypes:
tree = TreeModule



def params():
params = {}
if is_pyodide_context():
from manager import params

params = params.to_py()

return params


viur.prototypes = prototypes()

try:
Expand All @@ -49,5 +60,3 @@ class prototypes:
async def init():
resp = await viur.request.get("/config", renderer="vi")
viur.modules = resp["modules"]
if is_pyodide_context():
console.log("response = ", resp)
77 changes: 39 additions & 38 deletions src/assets/scriptor/csvwriter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .writer import MemoryWriter, DirectoryPickerWriter
from .writer import MemoryWriter, FilePickerWriter
from .utils import is_pyodide_context

if is_pyodide_context():
Expand All @@ -7,6 +7,8 @@
import csv
import json

from .logger import Logging as logging


class MemoryCsvWriter(MemoryWriter):
"""
Expand All @@ -18,7 +20,6 @@ class MemoryCsvWriter(MemoryWriter):
def __init__(self, *args, delimiter=";", formatter: callable = None):
super().__init__()
self._content.write("\ufeff") # excel needs this for right utf-8 decoding

if args:
self._writer = csv.DictWriter(
self._content,
Expand All @@ -39,7 +40,6 @@ def __init__(self, *args, delimiter=";", formatter: callable = None):

self._formatter: callable = formatter


@property
def writer(self):
return self._writer
Expand All @@ -56,10 +56,6 @@ def fmt(self, value):

if isinstance(value, list):
ret = ", ".join([self.fmt(v) for v in value])
if is_pyodide_context():
console.log(ret)
else:
print(ret)
return ret
elif isinstance(value, dict):
return json.dumps(value, sort_keys=True)
Expand All @@ -85,47 +81,52 @@ async def write(self, values: object):
def __str__(self):
return self._content.getvalue()

class FileSystemCsvWriter(MemoryCsvWriter):
class FileSystemCsvWriter(FilePickerWriter):
"""
Writer for CSV exports
"""

DEFAULT_FILE_NAME = "export.csv"

def __init__(self, *args, delimiter=";", formatter: callable = None, on_startup: callable = None):
super().__init__(*args, delimiter=delimiter, formatter=formatter)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._columns = []
self._writer: MemoryWriter = None
self._delimiter = ";"
self._formatter = None

def set_formatter(self, formatter: callable):
self._formatter = formatter

if len(args) > 0:
self.clear()
def set_columns(self, columns: list[str]):
self._columns = columns

def set_delimiter(self, delimiter: str):
self._delimiter = delimiter

self._directory_writer = None
self._on_startup = on_startup
self._file = None

async def flush(self):
if self._writer is None:
return

content = str(self._writer)
if content:
## Flushing the header
await super().write(content)

async def init(self):
await DirectoryPickerWriter.from_dialog(self.startup)

async def startup(self, handle):
await self._on_startup(handle)
self._writer.clear()

async def write(self, values: object):
if isinstance(values, dict):
assert isinstance(self._writer, csv.DictWriter)
self._writer.writerow({k: self.fmt(v) for k, v in values.items() if k in self._writer.fieldnames})
self.clear()
self._line_count += 1
elif isinstance(values, list):
if isinstance(self._writer, csv.DictWriter):
for row in values:
self.write(row)
else:
self._writer.writerow([self.fmt(v) for v in values])
async def __aenter__(self):
self._writer = MemoryCsvWriter(*self._columns, delimiter=self._delimiter, formatter=self._formatter)
await super().__aenter__()

if self._file:
self._file.write(str(self))
async def __aexit__(self, *args):
await self.flush()
await super().__aexit__(*args)

self.clear()
self._line_count += 1
else:
raise NotImplementedError(f"Don't know what to do with {repr(values)}")
async def write(self, values: object, should_flush: bool = False):
if self._writer is not None:
await self._writer.write(values)

if should_flush:
await self.flush()
1 change: 0 additions & 1 deletion src/assets/scriptor/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ async def input(text: str, *, title: str = "Input", type: str = "input", use_tim
manager.resultValue = None

if type == "date":
js.console.error(tmp)
return datetime.datetime.fromtimestamp(math.floor(tmp/1000.0))

return tmp
Expand Down
1 change: 0 additions & 1 deletion src/assets/scriptor/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class FilePickerReader(Picker):
async def on_startup(self):
if is_pyodide_context():
self._content = await (await self._file.getFile()).text()
console.log(f"content_type:{type(self._content)}")
else:
self._content = self._file.read()

Expand Down
2 changes: 1 addition & 1 deletion src/assets/scriptor/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __str__(self) -> str:
return self._content.getvalue()

def clear(self):
self._content.truncate()
self._content.truncate(0)

def download(self, name: str = ""):

Expand Down
1 change: 0 additions & 1 deletion src/components/CodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function editorFromTextArea(textarea: HTMLTextAreaElement, extensions: any)
tabStore.updateCode(props.keyValue, currentCode.value)
console.log("currentCode.value", currentCode.value, "initialCode.value", initialCode.value)
};
Expand Down
9 changes: 0 additions & 9 deletions src/components/CodeTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,28 @@ import { ProgressbarDetails } from '@/usepython/dist/interfaces';
const error = ref<string>("");
function acceptAlert() {
console.log("alert!");
pythonStore.py.sendDialogResult("alert", {}).then(() => {
console.log("sended succesfully!!");
});
}
function confirmSelect(value: boolean) {
console.log("alert!");
pythonStore.py.sendDialogResult("alert", value).then(() => {
console.log("value succesfully!!");
});
}
function sendInput(value: any) {
console.log("alert!");
pythonStore.py.sendDialogResult("input", value).then(() => {
console.log("value succesfully!!");
});
}
function sendSelect(value: any) {
console.log("alert!");
pythonStore.py.sendDialogResult("select", value).then(() => {
console.log("value sendSelect!!");
});
}
function getThemeByLevel(level: string)
{
console.log("level", level);
switch (level)
{
case "debug": return "neutral";
Expand Down
7 changes: 0 additions & 7 deletions src/components/Dialogs/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ if (!props.data.prefix) {
props.data.prefix = "";
}
console.log(`Props id: ${props.data.id}`)
const dialog = ref<HTMLDivElement>();
const inputText = ref<string>(props.data.initialText ? props.data.initialText : "");
const inputTextColorClass = ref<string>("");
Expand All @@ -69,11 +67,6 @@ onMounted(() => {
dialog.value.show();
})
watch(inputText, (a, b) => {
console.log(inputText.value);
})
const dialogStore = useDialogStore();
function destroyDialog() {
dialogStore.close(props.data.id);
Expand Down
Loading

0 comments on commit 28b9909

Please sign in to comment.