Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue.js UI implementation #4868

Merged
merged 92 commits into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
513331f
Start of vue
Karolis2011 Jun 2, 2018
d53cc66
I got no idea what exactly am I doing
Karolis2011 Jun 5, 2018
94c4830
Some updates
Karolis2011 Jun 6, 2018
e38ee58
Note: Edge is a bad browser
Karolis2011 Jun 6, 2018
fdaa4b8
Something is working
Karolis2011 Jun 6, 2018
18387b5
Made things behave
Karolis2011 Jun 7, 2018
41d7e02
It works kindda somehow
Karolis2011 Jun 7, 2018
138d26b
Things had to change
Karolis2011 Jun 8, 2018
47916ff
Ugh... I did messup this
Karolis2011 Jun 8, 2018
615c02e
Added state and un nano-ified one thing
Karolis2011 Jun 8, 2018
b519796
Some messups, again
Karolis2011 Jun 8, 2018
7489492
Documentation and few upgrades
Karolis2011 Jun 10, 2018
5b4edc8
Travis experimental chnages
Karolis2011 Jun 10, 2018
f758af5
Forget what last commit does with travis
Karolis2011 Jun 10, 2018
f63bbaa
Why I didn't try this earlier?
Karolis2011 Jun 10, 2018
941dbe9
Another attempt
Karolis2011 Jun 10, 2018
378f475
Fixing actual issue
Karolis2011 Jun 10, 2018
d3c72b1
This should work
Karolis2011 Jun 10, 2018
d48e11c
Maybe this one is better
Karolis2011 Jun 10, 2018
86bfcf9
This will probalby pass travis
Karolis2011 Jun 10, 2018
1a94042
Added compiled version of ui.
Karolis2011 Jun 11, 2018
6bd29f4
Added tests for varous mistakes that would have been done. And docs.
Karolis2011 Jun 11, 2018
fc7effb
Fix travis?
Karolis2011 Jun 11, 2018
6f149bc
Improvements to documentation
Karolis2011 Jun 11, 2018
2a0696d
Made things better
Karolis2011 Jun 15, 2018
ea3221d
Let's try to optimize travis
Karolis2011 Jun 15, 2018
cdd6af9
Steps torwards prefection
Karolis2011 Jun 15, 2018
567b1d9
Seems I need to trach time inside vueui
Karolis2011 Jun 16, 2018
54dc6a4
And fax machine receves first vueui interface
Karolis2011 Jun 18, 2018
14a2035
Finally made image things do image things
Karolis2011 Jun 19, 2018
9cf534e
Decumentation and minor improvements
Karolis2011 Jun 19, 2018
2b41747
Improvements to SSvueui
Karolis2011 Jun 21, 2018
bd27d85
Made theme basic usable
Karolis2011 Jun 21, 2018
9943d38
Added ligth theme for nanoui and made things somewhat better
Karolis2011 Jun 22, 2018
89510b1
Improves documentation
Karolis2011 Jun 22, 2018
1b6966a
Oh typo in names
Karolis2011 Jun 22, 2018
7724b74
This is only minor messup, I promise!
Karolis2011 Jun 22, 2018
012c85a
Tiny improvements
Karolis2011 Jun 26, 2018
dd6a55a
Seperated Css from javascript
Karolis2011 Jun 27, 2018
970e79d
NanoUI assets now take up 31.5% less space
Karolis2011 Jun 27, 2018
fc59b6f
Made themes selectable
Karolis2011 Jun 27, 2018
51b79e0
Ow, fixed flyaway
Karolis2011 Jun 28, 2018
1e99ee7
Added DM defined templates and object transfer
Karolis2011 Jun 28, 2018
bb75483
Fix to migration?
Karolis2011 Jun 28, 2018
e1fe396
Fix for migration 2?
Karolis2011 Jun 28, 2018
48b5620
I got told to use var char
Karolis2011 Jun 28, 2018
4647347
*sigh*
Karolis2011 Jun 28, 2018
ab7ebac
This works?
Karolis2011 Jun 28, 2018
7580331
Renames, and photocopier.
Karolis2011 Jun 28, 2018
bf7b437
Made things better
Karolis2011 Jun 29, 2018
0420487
More of travis insanity and happier Skull.
Karolis2011 Jun 30, 2018
3a3306c
Fix for execution flags
Karolis2011 Jun 30, 2018
843b939
Probably less stages are better
Karolis2011 Jun 30, 2018
b422335
Why not use cached vueui build?
Karolis2011 Jun 30, 2018
26eee5d
Changelog and test removal
Karolis2011 Jun 30, 2018
16f7446
Better themes
Karolis2011 Jul 1, 2018
29a42c8
\
Karolis2011 Jul 1, 2018
71bb0d6
Tiny fixes
Karolis2011 Jul 1, 2018
7933357
Probably peaple are happy.
Karolis2011 Jul 1, 2018
37e83ec
Seems like this has to change
Karolis2011 Jul 1, 2018
37b1351
FIX
Karolis2011 Jul 1, 2018
47237f3
Oh I forgot to remove this
Karolis2011 Jul 2, 2018
c968952
Migrated to vue-cli for less errors, also this now supports edge.
Karolis2011 Jul 3, 2018
99ab3d8
Fix docs and lint fail test
Karolis2011 Jul 3, 2018
7c2a814
Make erros comeout
Karolis2011 Jul 3, 2018
9f47994
Ruder linter
Karolis2011 Jul 3, 2018
eb0aa8c
Lint testing removal
Karolis2011 Jul 3, 2018
296c02d
Air control...
Karolis2011 Jul 5, 2018
56a2f54
Now it alows ghosts to see uis
Karolis2011 Jul 7, 2018
2e6edc3
Less responsive ui, potential fix for first issue.
Karolis2011 Jul 7, 2018
a4db9a4
Improvements of styles.
Karolis2011 Jul 8, 2018
c4e9253
Fixes and improvements
Karolis2011 Jul 8, 2018
8222224
Switch to font awsome
Karolis2011 Jul 11, 2018
aac3551
Merge remote-tracking branch 'upstream/development' into byvue
Karolis2011 Jul 15, 2018
7c9787d
Var monitors and a bit more (#4)
Karolis2011 Jul 19, 2018
df4c186
Docs and made things better
Karolis2011 Jul 21, 2018
4e62637
A little better
Karolis2011 Jul 21, 2018
d5c1cd0
Adds code owners
Karolis2011 Jul 28, 2018
4babde4
Merge remote-tracking branch 'upstream/development' into byvue
Karolis2011 Jul 28, 2018
17b60a6
USe of timers
Karolis2011 Jul 29, 2018
357c22a
More compactness
Karolis2011 Jul 29, 2018
0ce343e
More compact atmo control
Karolis2011 Jul 30, 2018
501d1f7
Updates, improvements and fixes
Karolis2011 Aug 2, 2018
83793d7
Cleanupname field on components was pointless and was confusing peapl…
Karolis2011 Aug 2, 2018
c9c34df
Fun of travis begins once again.
Karolis2011 Aug 2, 2018
8381602
I forgot to handle this
Karolis2011 Aug 2, 2018
b5ac84a
Betetr build process?
Karolis2011 Aug 2, 2018
59e47c1
Let's hope things workout
Karolis2011 Aug 2, 2018
3958d4a
Grammar and spell check
Karolis2011 Aug 2, 2018
bdac595
Merge branch 'development' into byvue
Karolis2011 Aug 2, 2018
17c59cf
Updates .gitignore to try to respect new policies
Karolis2011 Aug 2, 2018
6a9785c
Merge branch 'development' into byvue
skull132 Aug 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improves documentation
  • Loading branch information
Karolis2011 committed Jul 5, 2018
commit 89510b14633d34a94657e5f52a6defcadc0a2a47
2 changes: 1 addition & 1 deletion code/controllers/subsystems/processing/vueui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Byond Vue UI framework's management subsystem
/datum/controller/subsystem/processing/vueui/proc/get_open_uis(src_object)
var/src_object_key = SOFTREF(src_object)
if (!LAZYLEN(open_uis[src_object_key]))
return list()
return null

return open_uis[src_object_key]

Expand Down
8 changes: 5 additions & 3 deletions code/modules/vueui/ui.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ main ui datum.
* @param nactiveui - Vue component that is opened to render this ui's data
* @param nwidth - initial width of this ui
* @param nheight - initial height of this ui
* @param ntitle - title of this ui
* @param ndata - initial data. Optional.
* @param nstate - Topic state used for this ui's checks. Optional.
*
Expand Down Expand Up @@ -186,6 +187,7 @@ main ui datum.
/datum/vueuiui/proc/send_asset(var/name)
if (!QDELETED(user) || !user.client)
return
name = ckey(name)
if (name in assets)
user.client << browse_rsc(assets[name]["img"], "vueuiimg_" + ckey("\ref[assets[name]["img"]]") + ".png")

Expand Down Expand Up @@ -299,11 +301,11 @@ main ui datum.
update_status()

/**
* Generates json state object to be sent to ui.
* Returns actuve theme on varous conditions
*
* @return json object - text
* @return themes class - text
*/
/datum/vueuiui/proc/get_theme_class()
return ""
return "theme-nano dark-theme"

#undef UIDEBUG
65 changes: 43 additions & 22 deletions vueui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,50 @@ First we have to create a way to open ui, for example, a proc that's called when
/datum/mydatum/proc/open_ui()
var/datum/vueuiui/ui = SSvueui.get_open_ui(usr, src)
if (!ui)
ui = new(usr, src, "uiname", 300, 300)
ui = new(usr, src, "uiname", 300, 300, "Title of ui")
ui.open()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We open the UI that get_open_ui() returns? get_open_ui() can return a non-open UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in rare case, ui can get closed without server noticing it, this also makes sure if user clicks on machine again, it updates already open ui.

```
On first line we check if we already have open ui for this user, if we already have, then we just open it on last line, but if we don't have exisiting ui, we then create a new one.
On first line we check if we already have open ui for this user, if we already have, then we just open it on last line, but if we don't have existing ui, we then create a new one.
### Step 2: Provide data
But how we pass data to it? There is two ways to do it, first one is to pass inital data in constructor: `new(usr, src, "uiname", 300, 300, data)`. But it's recommended to use `vueui_data_change` proc for data feed to ui.
But how we pass data to it? There is two ways to do it, first one is to pass initial data in constructor: `new(usr, src, "uiname", 300, 300, "Title of ui", data)`. But it's recommended to use `vueui_data_change` proc for data feed to ui.
```DM
/datum/mydatum/vueui_data_change(var/list/newdata, var/mob/user, var/datum/vueuiui/ui)
if(!newdata)
// generate new data
return list("counter" = 0)
// Here we can add checks for diffrence of state and alter it
// Here we can add checks for difference of state and alter it
// or do actions depending on it's change
if(newdata["counter"] >= 10)
return list("counter" = 0)
return
```
Everytime DM receves of frontend state change it calls this proc to make sure that frontend state didn't go too far from actual data it should represent. If everything is alrigth with `newstate` and no push to frontend of data is needed then it should return `0` or `null`, else return data that should be pushed.
Every time server receives of frontend state change it calls this proc to make sure that frontend state didn't go too far from actual data it should represent. If everything is alright with `newstate` and no push to frontend of data is needed then it should return `0` or `null`, else return data that should be pushed.
### Step 3: Handle actions.
Simply use `Topic` proc to get ui action calls.
Simply use `Topic` proc to get ui action calls from ui.
```DM
/datum/vueuiuitest/Topic(href, href_list)
/datum/mydatum/Topic(href, href_list)
if(href_list["action"] == "test")
world << "Got Test Action! [href_list["data"]]"
return
```
### Step 4: Make ui itself.
It is recomended to [enable debuging](.#debug-ui) for this step to make things easier.
It is recommended to [enable debugging](.#debug-ui) for this step to make things easier.

To create ui itself, you need to create `.vue` file inside `\vueui\components\ui` and register it inside `\vueui\components\ui\index.js`. Example vueui file:
```vue
<template>
<div>
<p>{{ counter }}</p>
<bybutton :params="{ action: 'test', data: 'This is from ui.' }">Call topic</bybutton>
<bybutton @click="counter++">Increment counter</bybutton>
<vui-button :params="{ action: 'test', data: 'This is from ui.' }">Call topic</vui-button>
<vui-button @click="counter++">Increment counter</vui-button>
</div>
</template>

<script>
export default {
name: 'ui-uiname',
name: 'view-uiname',
data() {
return this.$root.$data.state; // Make data more easily acessible
return this.$root.$data.state; // Make data more easily accessible
}
};
</script>
Expand All @@ -67,28 +67,48 @@ p {
</style>
```
### Step 5: Compile
This ui framework requres whole ui to be compiled for changes to be avavible. Compilation requres Node.js runtime, what is opbtainable in varous ways, most common is install from official site. To do initial dependency setup run `npm install` to gather all dependencies nedded for ui. Single compilation can be done with `npm run compile`, but if you constantly do changes, then `npm run run` is more convienient, as it compiles everything as soon as change is detected.
This ui framework requires whole ui to be compiled for changes to be available. Compilation requires Node.js runtime, what is obtainable in various ways, most common is install from official site. To do initial dependency setup run `npm install` to gather all dependencies needed for ui. Single compilation can be done with `npm run compile`, but if you constantly do changes, then `npm run run` is more convenient, as it compiles everything as soon as change is detected.
# Notes
## Usefull APIs
## Useful APIs
### `SSvueui.check_uis_for_change(object)`
Asks all ui's to call `object`'s `vueui_data_change` proc to make all uis up tp date. Should be used when bigger change was done or action done change that would affect data.
Asks all ui's to call `object`'s `vueui_data_change` proc to make all uis up tp date. Should be used when bigger change was done or action done change that would affect global data.
### `SSvueui.get_open_uis(object)`
Gets a list of all open uis for specified object. This allows to interact with individual uis.
### `ui.activeui`
Determines currently active view component for this ui datum. Should be combines with `check_for_change()` or `push_change()`.
### `ui.header`
Determines header component that is used with this ui. Should be set before `ui.open()`.
### `ui.open()`
Tries to open this ui, and sends all necessary assets for proper ui rendering. If ui has no data, then calls `object.vueui_data_change(null ...)` to obtain initial ui data.
### `ui.send_asset(name)`
Sends singular asset to client for use in ui, after this call you might need to update client-side asset index. To do so call `push_change(null)`.
### `ui.add_asset(name, image)`
Adds asset for ui use, but does not send it to client. It will be sent in during next `ui.open()` call or if it's done manually with `ui.send_asset(name)` combined with `push_change(null)`.
### `ui.remove_asset(name)`
Removes asset from future use in ui. But client-side asset index isn't updated immediately to reflect removal of asset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe the asset cache supports removing assets. It's also global.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This asset part isn't part of asset cache, it's special server generated image asset management proc. Was designed mostly having records in mind.

### `ui.push_change(data).`
Pushes data change to client. This also pushes changes to metadata, what includes: title, world time, ui status, active ui component, client-side asset index.
### `ui.check_for_change(forcedPush)`
Checks with `object.vueui_data_change` if data has changed, if so, then change is pushed. If forcedPush is resolving to true, then it pushes change anyways.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is resolving to true" is a bit awkward; maybe "If forcedPush is true"?

### `ui.update_status()`
This call should be used if external change was detected. It checks if user still can use this ui, and what's it usability level.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it => its

## Debug ui
To enable debug mode and make figuring out things easier do following steps:
- Enable development mode inside wepbpack file by changing out commented out line
- Enable development mode inside webpack file by changing out commented out line
```js
\vueui\webpack.config.js: line 7
mode: 'production', // And comment this one out
//mode: 'development', // Uncomment this line to set mode to development
```
- Enable debuging inside ui datum. (This will always push new JS file each time open() is called and show data in JSON format at the end of ui)
- Enable debugging inside ui datum. (This will always push new JS file each time open() is called and show data in JSON format at the end of ui)
```DM
\code\modules\vueui\ui.dm: line 5
#define UIDEBUG 0 // Change 0 to 1
```
- Use `\vueui\template.html` in Internet explorer to use inspector to analyze ui behavour. Also don't forget to copy paste data data from actual ui to this debug ui.
- Use `\vueui\template.html` in Internet explorer to use inspector to analyze ui behaviour. Also don't forget to copy paste data from actual ui to this debug ui inside templates code.

## Vue sintax
You should look at [official Vuejs guide](https://vuejs.org/v2/guide/syntax.html). As it's more detailed and more acurarate than any explanation that could have been written here.
## Vue syntax
You should look at [official Vuejs guide](https://vuejs.org/v2/guide/syntax.html). As it's more detailed and more accurate than any explanation that could have been written here.
## UI components
### VuiButton `<vui-button>`
Button programmed to send provided data to ui object. Comes with icon support.
Expand All @@ -100,7 +120,7 @@ Example:
Parameters:
- `$slot` - Contents of button.
- `params` - key value pairs to send to `Topic` of object.
- `icon` - icon that should be used in that button. For avavible icons look at `\vueui\styles\theme-nano.scss`
- `icon` - icon that should be used in that button. For available icons look at `\vueui\styles\icons.scss`

### VuiProgress `<vui-progress>`
Simple progress bar for representing progress of a process or indicate status.
Expand All @@ -115,12 +135,13 @@ Parameters:
- `min` - minimum value of provided value's range. Should be used with binding.

### VuiImg `<vui-img>`
Wrapper for showing images added with ui proc `add_asset(var/name, var/image/img)`. Please note: images are sent to client when `open()` is called, if it's added after, then `send_asset(var/name)` should be used, also image index is sent with next data change, if imediate image change is needed then `check_for_change(1)` or `push_change(null)` should be used to send index.
Wrapper for showing images added with ui proc `ui.add_asset(name, image)`. Please note: images are sent to client when `open()` is called, if it's added after, then `send_asset(name)` should be used, also image index is sent with next data change, if immediate image change is needed then `check_for_change(1)` or `push_change(null)` should be used to send index.

Example:
```Vue
<vui-img name="my-image-name"></vui-img>
```
Parameters:
- `name` - name of asset to show that was sent to client.
Please note that regular `<img>` parameters apply here.