Skip to content

Commit

Permalink
Merge pull request #233 from alyf-de/custom-markers
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra authored Nov 10, 2023
2 parents a934f77 + ceeb615 commit 6f607e5
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 2 deletions.
42 changes: 42 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,4 +320,46 @@ curl --location "$BASE_URL/api/method/landa.api.change_log?from_datetime=2023-01
}
]
}
```

## Custom Icon

Get a list of custom icons.

- `GET /api/method/landa.api.custom_icon`

Parameters:

- `id` (optional): return only data of the custom icon with this ID.

### Example Requests

> Remember set the environment variable `BASE_URL` to the URL of your LANDA instance. For example like this: `export BASE_URL=https://lvsa-landa.de`
Get all custom icons:

```bash
curl --location "$BASE_URL/api/method/landa.api.custom_icon"
```

Get a specific custom icon:

```bash
curl --location "$BASE_URL/api/method/landa.api.custom_icon?id=parken-verboten"
```

### Example Response

The response is always a list of dictionaries, like this:

```json
{
"message": [
{
"id": "parken-verboten",
"title": "Parken verboten",
"url": "$BASE_URL/files/no-parking-gd723fe33f_640.png"
}
]
}
```
16 changes: 16 additions & 0 deletions landa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,19 @@ def change_log(from_datetime: str):

result = get_changed_data(from_datetime)
return get_formatted_changes(result)


@frappe.whitelist(allow_guest=True, methods=["GET"])
def custom_icon(id: str = None) -> str:
"""Return the custom icon for the given icon name."""
from frappe.utils.data import get_url

filters = {}
if id and isinstance(id, str):
filters["name"] = id

icons = frappe.get_all("Custom Icon", filters=filters, fields=["name as id", "title", "icon"])
for icon in icons:
icon["url"] = get_url(icon.pop("icon"))

return icons
2 changes: 2 additions & 0 deletions landa/startup/boot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import frappe

from landa.utils import get_current_member_data
from landa.water_body_management.doctype.custom_icon.custom_icon import get_icon_map


def boot_session(bootinfo):
if frappe.session.user == "Guest":
return

bootinfo.landa = get_current_member_data()
bootinfo.icon_map = get_icon_map()
3 changes: 3 additions & 0 deletions landa/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ Privacy Policy,Datenschutzerklärung,
Imprint,Impressum,
Toggle HTML,HTML umschalten,
Rent per Year,Pachtzins pro Jahr,
Icon,Symbol,
Custom Marker,Spezielle Markierungen,
Please attach an icon file.,Bitte hängen Sie eine Symbol-Datei an.,
Empty file.
10 changes: 10 additions & 0 deletions landa/water_body_management/doctype/custom_icon/custom_icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2023, ALYF GmbH and contributors
// For license information, please see license.txt

frappe.ui.form.on("Custom Icon", {
refresh: function (frm) {
if (!frm.is_new() && !frm.doc.icon) {
frm.dashboard.set_headline(__("Please attach an icon file."));
}
},
});
67 changes: 67 additions & 0 deletions landa/water_body_management/doctype/custom_icon/custom_icon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"actions": [],
"creation": "2023-07-18 20:42:02.895070",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"title",
"icon"
],
"fields": [
{
"fieldname": "title",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Title",
"reqd": 1
},
{
"fieldname": "icon",
"fieldtype": "Attach Image",
"label": "Icon",
"mandatory_depends_on": "eval: !doc.__islocal"
}
],
"image_field": "icon",
"links": [],
"make_attachments_public": 1,
"modified": "2023-11-10 12:54:07.987734",
"modified_by": "Administrator",
"module": "Water Body Management",
"name": "Custom Icon",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "LANDA State Organization Employee",
"share": 1,
"write": 1
},
{
"read": 1,
"role": "All"
}
],
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "title"
}
15 changes: 15 additions & 0 deletions landa/water_body_management/doctype/custom_icon/custom_icon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2023, ALYF GmbH and contributors
# For license information, please see license.txt

import frappe
from frappe.model.document import Document


class CustomIcon(Document):
def autoname(self):
self.name = "-".join(self.title.lower().split(" "))


def get_icon_map():
icons = frappe.get_all("Custom Icon", fields=["name", "icon"])
return {icon.name: icon.icon for icon in icons}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023, ALYF GmbH and Contributors
# See license.txt

# import frappe
import unittest


class TestCustomIcon(unittest.TestCase):
pass
17 changes: 17 additions & 0 deletions landa/water_body_management/doctype/water_body/water_body.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
div[data-fieldname="icon_preview"] {
height: 24px;
width: 24px;
margin: auto !important;
}

input[type=range]::-webkit-slider-thumb {
background: var(--primary);
}

input[type=range]::-moz-range-thumb {
background: var(--primary);
}

input[type=range]::-ms-thumb {
background: var(--primary);
}
28 changes: 28 additions & 0 deletions landa/water_body_management/doctype/water_body/water_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,33 @@ frappe.ui.form.on("Water Body", {
) {
frm.disable_form();
}
bind_rotation_event(frm);
frm.set_query(
"icon",
function (doc) {
return {
filters: {
icon: ["is", "set"]
},
};
}
);
},
icon: function (frm) {
if (frm.doc.icon) {
bind_rotation_event(frm);
}
},
});

function bind_rotation_event(frm) {
const icon_rotation = document.getElementById("icon_rotation");
const icon_preview = frm.fields_dict.icon_preview.wrapper.getElementsByTagName("img")[0];
icon_rotation.addEventListener(
"input",
function (evt) {
icon_preview.style.transform = `rotate(${evt.target.value}deg)`;
frm.rotation_angle = evt.target.value;
}
);
}
63 changes: 61 additions & 2 deletions landa/water_body_management/doctype/water_body/water_body.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
"section_break_95kcp",
"water_body_special_provisions",
"section_break_msjqv",
"location"
"location",
"custom_marker_section",
"icon",
"rotation",
"column_break_jorfc",
"icon_path",
"icon_preview"
],
"fields": [
{
Expand Down Expand Up @@ -220,6 +226,47 @@
"fieldname": "current_information_expires_on",
"fieldtype": "Date",
"label": "Current Information Expires On"
},
{
"fieldname": "icon",
"fieldtype": "Link",
"label": "Icon",
"options": "Custom Icon",
"permlevel": 2
},
{
"depends_on": "icon",
"fieldname": "rotation",
"fieldtype": "HTML",
"label": "Rotation",
"options": "<label for=\"icon_rotation\">Drehung</label>\n<input class=\"custom-range\" id=\"icon_rotation\" max=\"180\" min=\"-180\" step=\"15\" type=\"range\">",
"permlevel": 2
},
{
"fieldname": "column_break_jorfc",
"fieldtype": "Column Break"
},
{
"depends_on": "icon",
"fieldname": "icon_preview",
"fieldtype": "Image",
"label": "Icon Preview",
"options": "icon_path",
"permlevel": 2
},
{
"fetch_from": "icon.icon",
"fetch_if_empty": 1,
"fieldname": "icon_path",
"fieldtype": "Attach Image",
"hidden": 1,
"label": "Icon Path",
"permlevel": 2
},
{
"fieldname": "custom_marker_section",
"fieldtype": "Section Break",
"label": "Custom Marker"
}
],
"links": [
Expand All @@ -236,7 +283,7 @@
"link_fieldname": "water_body"
}
],
"modified": "2023-06-13 11:55:53.677192",
"modified": "2023-11-10 12:45:58.137879",
"modified_by": "Administrator",
"module": "Water Body Management",
"name": "Water Body",
Expand Down Expand Up @@ -301,6 +348,18 @@
"read": 1,
"role": "LANDA Regional Water Body Management",
"write": 1
},
{
"permlevel": 2,
"read": 1,
"role": "LANDA State Organization Employee",
"write": 1
},
{
"permlevel": 2,
"read": 1,
"role": "LANDA Regional Water Body Management",
"write": 1
}
],
"quick_entry": 1,
Expand Down

0 comments on commit 6f607e5

Please sign in to comment.