Skip to content

Commit

Permalink
feature(form): connect rdp form to issue template
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Apr 29, 2024
1 parent e15273f commit 543731b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
70 changes: 47 additions & 23 deletions qtribu/gui/form_rdp_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# standard
from functools import partial
from pathlib import Path
from typing import Union
from urllib.parse import urlparse

# PyQGIS
Expand All @@ -19,7 +20,7 @@
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox

# plugin
from qtribu.__about__ import DIR_PLUGIN_ROOT
from qtribu.__about__ import DIR_PLUGIN_ROOT, __title__, __version__
from qtribu.constants import GEORDP_NEWS_CATEGORIES, GEORDP_NEWS_ICONS, GeotribuImage
from qtribu.toolbelt import NetworkRequestsManager, PlgLogger, PlgOptionsManager
from qtribu.toolbelt.commons import open_url_in_browser
Expand All @@ -29,6 +30,9 @@ class RdpNewsForm(QDialog):
"""QDialog form to submit a news to a next GeoRDP."""

LOCAL_CDN_PATH: Path = Path().home() / ".geotribu/cdn/"
ISSUE_FORM_BASE_URL: str = (
"https://github.com/geotribu/website/issues/new?template=RDP_NEWS.yml"
)

def __init__(self, parent=None):
"""Constructor.
Expand Down Expand Up @@ -83,11 +87,9 @@ def __init__(self, parent=None):
"https://contribuer.geotribu.fr/rdp/add_news/",
)
)
self.btn_box.button(QDialogButtonBox.Open).setText(self.tr("Load draft"))
self.btn_box.button(QDialogButtonBox.Open).clicked.connect(self.on_btn_open)
self.btn_box.button(QDialogButtonBox.Save).setText(self.tr("Save draft"))
self.btn_box.button(QDialogButtonBox.Ok).setText(self.tr("Submit"))
self.btn_box.button(QDialogButtonBox.Ok).clicked.connect(self.on_btn_submit)
self.btn_box.button(QDialogButtonBox.Ok).setDefault(True)
self.btn_box.button(QDialogButtonBox.Ok).setText(self.tr("Submit"))

def cbb_icon_populate(self) -> None:
"""Populate combobox of news icons."""
Expand Down Expand Up @@ -170,22 +172,7 @@ def generate_preview(self) -> None:
self.txt_preview.clear()
self.txt_preview.setMarkdown(md_txt)

def on_btn_open(self):

self.log("piouou")

def on_btn_save(self):

self.log("piouou")

def on_btn_submit(self) -> bool:
"""Check if required form fields are correctly filled and submit to Github issue
form.
:return: False if some check fails. True and emit accepted() signal if
everything is ok.
:rtype: bool
"""
def check_required_fields(self) -> bool:
invalid_fields = []
error_message = ""

Expand Down Expand Up @@ -252,6 +239,43 @@ def on_btn_submit(self) -> bool:
for wdg in invalid_fields:
wdg.setStyleSheet("border: 1px solid red;")
return False

return True

def on_btn_submit(self) -> Union[bool, str, None]:
"""Check if required form fields are correctly filled and submit to Github issue
form.
:return: False if some check fails. True and emit accepted() signal if
everything is ok.
:rtype: bool
"""
if not self.check_required_fields():
return False

completed_url = (
f"{self.ISSUE_FORM_BASE_URL}"
f"&in_author_name={self.wdg_author.lne_firstname.text()} "
f"{self.wdg_author.lne_lastname.text()}"
f"&in_author_mail={self.wdg_author.lne_email.text()}"
f"&in_author_linkedin={self.wdg_author.lne_linkedin_account.text()}"
f"&in_author_mastodon={self.wdg_author.lne_mastodon_account.text()}"
f"&in_author_twitter={self.wdg_author.lne_twitter_account.text()}"
f"&in_author_license=true"
f"&cb_author_content_relationship={self.chb_transparency.isChecked()}"
f"&dr_news_category={self.cbb_category.currentText()}"
f"&in_news_title={self.lne_title.text()}"
f"&in_news_icon={self.cbb_icon.currentText()}"
f"&tx_news_content={self.txt_body.toPlainText()}"
f"&tx_misc_comment={self.txt_comment.toPlainText()}"
f"&title=[GeoRDP] {self.lne_title.text()} - {__title__} {__version__}"
)
self.log(message=f"Opening issue form: {completed_url}", log_level=4)
url_opened = open_url_in_browser(url=completed_url)
if url_opened:
self.log(message="URL opened!", push=True, duration=2, log_level=0)
else:
super().accept()
return True
self.log(message="URL NOT OPENEDED :(", push=True, duration=4, log_level=2)

super().accept()
return True
11 changes: 4 additions & 7 deletions qtribu/gui/form_rdp_news.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>763</width>
<width>891</width>
<height>1156</height>
</rect>
</property>
Expand Down Expand Up @@ -267,14 +267,14 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="lbl_transparency">
<property name="text">
<string>Transparency:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="chb_transparency">
<property name="text">
<string>I'm not related to the published content. If not, I give some details in the comment area.</string>
</property>
Expand Down Expand Up @@ -321,13 +321,10 @@ p, li { white-space: pre-wrap; }
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::Open|QDialogButtonBox::Save</set>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="AuthoringWidget" name="wdg_author" native="true"/>
</item>
<item row="11" column="1">
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down

0 comments on commit 543731b

Please sign in to comment.