Skip to content

Commit 07b5fd0

Browse files
committed
feature: data-popup-title and addresses Issue#38 when formProp is missing, updated docs
1 parent 0cca0fe commit 07b5fd0

File tree

3 files changed

+105
-49
lines changed

3 files changed

+105
-49
lines changed

README.md

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
1-
# Clone mercurial repository.
1+
# Development Setup
2+
3+
### Clone mercurial repository.
4+
```shell
25
hg clone http://hg.code.sf.net/p/roundup/code roundup
6+
```
37

4-
# Navigate to roundup, then git clone tracker only repo.
8+
### Make python virtual env and activate it
9+
```shell
510
cd roundup
11+
python -m venv .
12+
```
13+
#### For linux and mac
14+
```shell
15+
source bin/activate
16+
```
17+
#### For windows powershell
18+
```shell
19+
.\scripts\Activate.ps1
20+
```
21+
22+
### Install roundup
23+
```shell
24+
python -m pip install .
25+
```
26+
27+
### Clone tracker only repo.
28+
```shell
629
git clone https://github.com/UMB-CS-682-Team-03/tracker.git
30+
```
731

8-
# Init the demo tracker
9-
python3 demo.py -b sqlite
32+
### Init the demo tracker with default ./demo
33+
```shell
34+
roundup-demo -b sqlite
35+
```
1036

11-
# Move the files from tracker dir to demo dir
37+
### Move the files from tracker dir to demo dir
38+
#### For linux and mac
39+
```shell
1240
cp -r ./tracker/**/* ./demo
1341
cp -r ./tracker/.git ./tracker/.gitignore ./demo
42+
```
43+
#### For windows powershell
44+
```shell
45+
xcopy .\tracker .\demo /s #say yes to all
46+
```
1447

15-
# Delete the tracker dir
16-
rm -rf ./tracker
17-
18-
# Now you are setup open the roundup folder in VScode.
19-
# Any new changes are only to be done in demo dir
20-
# git is initialised to track origin in demo dir
48+
1. Now you are done setting up developing environment.
49+
2. Open the roundup folder in VScode.
50+
3. Any new changes are only to be done in demo directory.
51+
4. git is initialized to track origin in demo directory (for windows check if .git folder is copied to the demo)
2152

2253
# Roundup - Classhelper
2354
## `<roundup-classhelper>`
@@ -75,81 +106,87 @@ In addition to keyboard navigation, the `<roundup-classhelper>` component can be
75106

76107
* If present, users can click on the submit button or any other controls in this section to trigger the submission or update action.
77108

78-
### Admin guide for deploying roundup-classhelper to an existing tracker
109+
## Guide for using/deploying roundup-classhelper in a tracker
79110
#### Which tag to use and where to place it.
80111
* To customise your own classhelper you can introduce of the `<roundup-classhelper>` web component.
81112

82-
* Locate the appropriate template files (e.g., issue.html) where you want to use the <roundup-classhelper>.
113+
* Locate the appropriate template files (e.g., issue.html) where you want to use the `<roundup-classhelper>`.
83114

84-
* Wrap the existing ClassHelper link with the <roundup-classhelper> tag.
115+
* Wrap the existing ClassHelper link with the `<roundup-classhelper>` tag.
85116
##### Before the code would look like this.
86117
```html
87118
<th i18n:translate="">Nosy List</th>
88-
<td>
89-
<span tal:replace="structure context/nosy/field" />
90-
<span tal:condition="context/is_edit_ok" tal:replace="structure
91-
python:db.user.classhelp('username,realname,address', property='nosy', width='600')" />
92-
<br>
93-
</td>
119+
<td>
120+
<span tal:replace="structure context/nosy/field" />
121+
<span tal:condition="context/is_edit_ok" tal:replace="structure
122+
python:db.user.classhelp('username,realname,address', property='nosy', width='600'" />
123+
</td>
94124
```
95125

96126
##### After adding the `<roundup-classhelper>`, it should look like this.
97127
```html
98128
<th i18n:translate="">Nosy List</th>
99-
<td>
100-
<span tal:replace="structure context/nosy/field" />
101-
<roundup-classhelper data-search-with="username,phone,roles[]">
102-
<span tal:condition="context/is_edit_ok" tal:replace="structure
103-
python:db.user.classhelp('username,realname,address', property='nosy', width='600')" />
104-
</roundup-classhelper>
105-
<br>
106-
</td>
129+
<td>
130+
<span tal:replace="structure context/nosy/field" />
131+
<roundup-classhelper data-popup-title="Nosy List Classhelper - {itemDesignator}" data-search-with="username,phone,roles[]">
132+
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.user.classhelp('username,realname,address', property='nosy', width='600')" />
133+
</roundup-classhelper>
134+
</td>
107135
```
108136

109-
#### Setting Attributes
110-
* Set the `data-search-with` attribute to specify the fields that can be used for searching (e.g., `data-search-with="title,status,keyword"`).
137+
### Setting Attributes on `</roundup-classhelper>`
138+
139+
#### Setting the `data-popup-title` attribute is optional.
140+
141+
* Adding `data-popup-title` changes the title of the popup window with the value of the attribute.
142+
* `{itemDesignator}` can be used inside the attribute value to replace it with the current classhelper usage context.
143+
* eg. `data-popup-title="Nosy List Classhelper - {itemDesginator}"` will have the popup window title `Nosy List Classhelper - users`
144+
145+
#### Setting the `data-search-with` attribute is optional.
146+
147+
* Adding `data-search-with` specifies the fields that can be used for searching (e.g., `data-search-with="title,status,keyword"`).
111148

112-
* Optionally, customize the search parameters using the following syntax:
113-
* `"status[]"`: Displays a dropdown for the "status" field, showing all possible values.
149+
* Optionally, customize the search parameters using the following syntax:
150+
* `"status[]"`: Displays a dropdown for the "status" field, showing all possible values.
114151
```html
115152
<roundup-classhelper data-search-with="title,status[], keyword[]">
116153
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=100)" />
117154
</roundup-classhelper>
118155
```
119-
* `"keyword[]+name"`: Sorts the "keyword" dropdown in ascending order by name.
156+
* `"keyword[]+name"`: Sorts the "keyword" dropdown in ascending order by name.
120157
```html
121158
<roundup-classhelper data-search-with="title,status[],keyword[]+name">
122159
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=100)" />
123160
</roundup-classhelper>
124161
```
125-
* `"keyword[]-name"`: Sorts the "keyword" dropdown in descending order by name.
162+
* `"keyword[]-name"`: Sorts the "keyword" dropdown in descending order by name.
126163
```html
127164
<roundup-classhelper data-search-with="title,status[],keyword[]-name">
128165
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=100)" />
129166
</roundup-classhelper>
130167
```
131168
* If the `roles` field cannot be displayed as a dropdown, it will be treated as a text-only match.
132169

133-
#### User ClassHelper
170+
### User ClassHelper
134171
* To emulate the normal user ClassHelper behavior (e.g., for username and roles), use the following attribute values:
135172
``` html
136173
<roundup-classhelper data-search-with="username,roles[]">
137174
<!-- ClassHelper content -->
138175
</roundup-classhelper>
139176
```
140177

141-
#### Fallback Mechanism
142-
If the user's browser doesn't support web components, the `<roundup-classhelper>` will automatically fall back to the existing ClassHelper link.
178+
### Fallback Mechanism
179+
If the user's browser doesn't support web components, the `<roundup-classhelper>` will automatically fall back to use ClassHelper link.
143180

144181
<img src="./doc-assets/image-5.png" alt="Image Title" width="40%">
145182

146-
#### Error Handling
147-
* In case of errors, the component will display relevant messages to the user.(component will notify the user)
183+
### Error Handling
184+
* In case of errors, the component will use the fallback to use ClassHelper link while alerting the user.
148185
* For further debugging, users can open the browser console and inspect the results.
149186

150187

151188

152-
#### Refreshing `classhelper.css`
189+
### Refreshing `classhelper.css`
153190
In case of issues with the `<roundup-classhelper>` component, you can try refreshing the `classhelper.css` file by following these steps:
154191
* Open your Roundup issue tracker in a web browser.
155192
* In the address bar, append `@@file/classhelper.css` to the end of your Roundup URL. For example, if your Roundup URL is `http://example.com/tracker`, the URL you should visit would be `http://example.com/tracker/@@file/classhelper.css`

html/classhelper.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const CSS_STYLESHEET_FILE_NAME = "@@file/classhelper.css";
2424

2525
const CLASSHELPER_TAG_NAME = "roundup-classhelper";
2626
const CLASSHELPER_ATTRIBUTE_SEARCH_WITH = "data-search-with";
27+
const CLASSHELPER_ATTRIBUTE_POPUP_TITLE = "data-popup-title";
28+
const CLASSHELPER_ATTRIBUTE_POPUP_TITLE_ITEM_DESIGNATOR_LOOKUP = "{itemDesignator}";
2729
const CLASSHELPER_POPUP_FEATURES = (width, height) => `popup=yes,width=${width},height=${height}`;
2830
const CLASSHELPER_POPUP_URL = "about:blank";
2931
const CLASSHELPER_POPUP_TARGET = "_blank";
@@ -48,7 +50,7 @@ const ALTERNATIVE_DROPDOWN_PATHNAMES = {
4850
* ------------
4951
* The helpurl must be wrapped under this web component(user named html tag).
5052
* ```html
51-
* <roundup-classhelper data-search-with="title,status[],keyword[]+name">
53+
* <roundup-classhelper data-popup-title="info - {itemDesignator} - Classhelper" data-search-with="title,status[],keyword[]+name">
5254
* ( helpurl template here, this can be tal, chameleon, jinja2.
5355
* In HTML DOM this is an helpurl anchor tag.
5456
* )
@@ -78,6 +80,11 @@ const ALTERNATIVE_DROPDOWN_PATHNAMES = {
7880
* optionally with "[]" present to a column name there can be
7981
* [+ or -] with succeeding "id" or "name" for sorting dropdown.
8082
*
83+
* The data-popup-title attribute of the web component is optional.
84+
* the value of this attribute is the title of the popup window.
85+
* the user can use "{itemDesignator}" in the title to replace in the attribute value.
86+
* and the current context of classhelper will replace "{itemDesignator}".
87+
*
8188
*/
8289
class ClassHelper extends HTMLElement {
8390

@@ -933,22 +940,34 @@ class ClassHelper extends HTMLElement {
933940
}
934941

935942
const itemDesignator = window.location.pathname.split("/").at(-1);
936-
let titleText = `${itemDesignator} - Classhelper`;
937-
if (props.formProperty) {
938-
// main window lookup for the label of the form property
939-
const label = document.getElementsByName(props.formProperty).item(0).parentElement.previousElementSibling;
940-
titleText = label.textContent + " - " + titleText;
943+
let titleText;
944+
945+
if (this.dataset.popupTitle) {
946+
titleText = this.dataset.popupTitle;
947+
const hasItemDesignator = titleText.includes(CLASSHELPER_ATTRIBUTE_POPUP_TITLE_ITEM_DESIGNATOR_LOOKUP);
948+
if (hasItemDesignator) {
949+
titleText = titleText.replace(CLASSHELPER_ATTRIBUTE_POPUP_TITLE_ITEM_DESIGNATOR_LOOKUP, itemDesignator);
950+
}
951+
} else {
952+
titleText = `${itemDesignator} - Classhelper`;
953+
if (props.formProperty) {
954+
// main window lookup for the label of the form property
955+
const field = document.getElementsByName(props.formProperty).item(0);
956+
if (field) {
957+
const label = field.parentElement.previousElementSibling
958+
titleText = label.textContent + " - " + titleText;
959+
}
960+
}
941961
}
942962

943963
const titleTag = document.createElement("title");
944964
titleTag.textContent = titleText;
965+
head.appendChild(titleTag);
945966

946967
const styleSheet = document.createElement("link");
947968
styleSheet.rel = "stylesheet";
948969
styleSheet.type = "text/css";
949970
styleSheet.href = this.trackerBaseURL + '/' + CSS_STYLESHEET_FILE_NAME;
950-
951-
head.appendChild(titleTag);
952971
head.appendChild(styleSheet);
953972

954973
if (this.dataset.searchWith) {

html/issue.item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<th i18n:translate="">Superseder</th>
5757
<td>
5858
<span tal:replace="structure python:context.superseder.field(showid=1, size=20)" />
59-
<roundup-classhelper data-search-with="title,status,keyword[]-name">
59+
<roundup-classhelper data-popup-title="Superseder Classhelper - {itemDesignator}" data-search-with="title,status,keyword[]-name">
6060
<span tal:condition="context/is_edit_ok" tal:replace="structure python:db.issue.classhelp('id,title', property='superseder', pagesize=100)" />
6161
</roundup-classhelper>
6262
<span tal:condition="context/superseder">

0 commit comments

Comments
 (0)