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

API for local files (up|down)loading #243

Merged
merged 5 commits into from Nov 1, 2019

Conversation

johnd0e
Copy link
Contributor

@johnd0e johnd0e commented Aug 28, 2019

  • Implement local file(s) loading/saving helpers for non-IITCm environment
  • Provide environment-independent API (utils_file.js):
  • Make use of mentioned enhancements, to unify files import/export in draw-tools and bookmarks.
    (Previously import/export was implemented for IITCm only)

@johnd0e
Copy link
Contributor Author

johnd0e commented Aug 28, 2019

Some functions are (by their nature) strictly specific to environment.

  • Load/Save file
  • Copy to clipboard
  • Share

There are no Web api to make that directly, but it's possible using some techniques.
But that techniques cannot be applied in IITCm's WebView (as it's not full-featured browser).
So for IITCm it's developers have implemented own functions (placed in android namespace).

This fragmentation is bad.
Most plugins developers are lazy, and do not bother to implement actions missing in some environment.
E.g. till now it was not possible to use file import/export in bookmarks/draw-tools on desktop.

So I'm going to implement some new environment-independent api functions.

@johnd0e
Copy link
Contributor Author

johnd0e commented Aug 29, 2019

// @function saveFile(data: String, filename?: String, dataType? String)
// Save data to file with given filename, using IITCm file chooser, or generic browser routine.
// `dataType` can be set to filter IITCm file chooser filetypes.

Edit
I've just realized, that more proper way'd be #244 - implement relevant parts in IITCm (and then just add simple helper functions).

But we have ho Java developer at the moment..

@johnd0e johnd0e added the WIP Work in progress || Proof of the concept label Aug 30, 2019
@johnd0e johnd0e force-pushed the save-load-routines branch 3 times, most recently from 15873bf to d12bc6b Compare September 5, 2019 15:34
@johnd0e johnd0e force-pushed the save-load-routines branch 2 times, most recently from 9c9c481 to 7f98ef1 Compare September 7, 2019 14:40
@johnd0e
Copy link
Contributor Author

johnd0e commented Sep 7, 2019

// @function loadFiles(options: Object): Object (L.Evented instance)
// Instantiates a `L.Evented` object, and initiates file chooser dialog,
// using methods, depending on environment:
// - desktop: simulating click on hidden `input` HTML element, created using specified `options`
// - IITCm (android): using `window.requestFile` (`options` ignored).

// @event init: Event
// Fired before file is read.
// `Event` object has additional property `file`: contains processed [`File`](https://w3c.github.io/FileAPI/#dfn-file) object.
// Note: in order to stop further processing of the file
// handler may throw error (is's safe as errors are caught)

// @event init:error: Event
// Fired on errors arised in 'init' handler(s).
// `Event` object has following additional properties:
// `file`: contains processed [`File`](https://w3c.github.io/FileAPI/#dfn-file) object.
// `error`: `Error` object.
// Note: if no handlers found for `error:init` then default one will be attached (`console.warn`)

// @event load: Event
// `Event` object has following additional properties:
// `reader`: raw instance of [`FileReader`](https://w3c.github.io/FileAPI/#APIASynch) interface
// `file`: raw instance of [`File`/`Blob`](https://w3c.github.io/FileAPI/#dfn-file)
// `originalEvent`: raw [event](https://w3c.github.io/FileAPI/#events)

// @event loaded: Event
// Fired after all files are processed (either with success or with error).

@HubertZhang
Copy link
Contributor

For load file part, what’s the problem with default input button? I think using input button and implementing proper methods in IITCm are more safe.

Also I suggest we separate file apis with Leaflet. It’s weird that we put file reader under L namespace.

@johnd0e
Copy link
Contributor Author

johnd0e commented Sep 7, 2019

  1. It is input internally.
    Yes, I wait you to enhance IITCm, so some things in this PR is temporary.
    It's draft, you see.

@johnd0e
Copy link
Contributor Author

johnd0e commented Sep 7, 2019

  1. At first I've made some custom homebrew helper utilities.
    Then I've thrown away it, and rewrite as clean and simple classes. And yes, based on leaflet.

So let's talk about leaflet. Our project in general is closely connected with leaflet already.
It has event system powerful enough, and flexible class system.
So why not reuse it for our purposes?

But we can put some high-level function (or two) into other namespace, if you find it less confusing.

The function will use IITCm filechooser, or generic browser routines.

bookmarks and draw-tools adapted to use the function,
so now it's possible to export data to files on desktop too
The function will use IITCm filechooser, or generic browser routines.

bookmarks and draw-tools adapted to use the function,
so now it's possible to import data from files on desktop too
After IITC-CE#250 we can load files in IITCm with common Web API.
(or use L.FileReader/L.FileListLoader as helpers, but it's optional)
It's left for compatibility.
Internally it uses new methods.
@johnd0e johnd0e added this to Priority in Track features for next release via automation Oct 8, 2019
@johnd0e johnd0e requested a review from modos189 October 8, 2019 20:44
@johnd0e johnd0e mentioned this pull request Oct 9, 2019
9 tasks
@AlfonsoML
Copy link

I second the opinion that placing any IITC functions under L. is quite strange.
There are issues opened about removing stuff from window. and providing a better API, and instead of starting here with for example a global IITC. you're placing this functions under L. so they will be very hard to notice for anyone trying to find out the API provided by IITC,
At least in window. we're used about the common properties and we can notice things that are out of place, but very few people will be notice a modified L.

@johnd0e
Copy link
Contributor Author

johnd0e commented Oct 9, 2019

Those are not IITC-specific functions. And those are exactly Leaflet classes.
As for naming you can read what is concerned as best practises here: https://leafletjs.com/examples/extending/extending-1-classes.html#naming-conventions

Actually in the same manner we already use a lot of other 3rd-party Leaflet plugins - check externals subdirectory.

@johnd0e
Copy link
Contributor Author

johnd0e commented Oct 9, 2019

Another example: see master branch, boot.js:616.
There is L.DivIcon.ColoredSvg defined, also our Leaflet class.
And there are more in pending PRs.

But you are right, we should document all these things.

@johnd0e johnd0e moved this from Priority to Testing in Track features for next release Oct 16, 2019
@johnd0e johnd0e changed the title New API functions common both to desktop and IITCm API for local files (up|down)loading Oct 16, 2019
@johnd0e johnd0e removed the WIP Work in progress || Proof of the concept label Oct 17, 2019
@johnd0e johnd0e marked this pull request as ready for review October 17, 2019 06:38
@johnd0e johnd0e added core development general development issue enhancement New feature or request plugin labels Oct 30, 2019
@johnd0e johnd0e removed the request for review from modos189 November 1, 2019 14:40
@johnd0e johnd0e merged commit 1aa2295 into IITC-CE:master Nov 1, 2019
Track features for next release automation moved this from Testing to Merged Nov 1, 2019
@johnd0e johnd0e deleted the save-load-routines branch November 1, 2019 14:40
johnd0e added a commit to johnd0e/ingress-intel-total-conversion that referenced this pull request Dec 5, 2019
- Update most upstream sources, and significantly enhance several plugins IITC-CE#134 (a lot of changes, follow the link to see)
- Fix performance drop when displaying a large number of ornaments IITC-CE#181
- Improve RegionScoreboard IITC-CE#179 © McBen + some fixes
- Remove confusing message from artifacts dialog IITC-CE#216
- Portal info: display coordinates without angled brackets IITC-CE#233
- Leaflet controls: prevent mobile style on desktop IITC-CE#189
- Increase map renderer padding (and make value customizable) IITC-CE#201
- Portal info: `shielding` tooltip: round mitigation `excess` to cope with lack of js float precision IITC-CE#279

- Fix miscellaneous bugs in core and plugins IITC-CE#157
- Change default intel url (to match stock) IITC-CE#267

- Implement plugins priority control IITC-CE#205
- Stop console 'spam' using customizable logger IITC-CE#235
- Consistent errors throwing IITC-CE#248
- API for local files (up|down)loading IITC-CE#243
- Remove some unused stuff from window object IITC-CE#101
- Refactor to use common function `window.makePermalink` (utils_misc.js) IITC-CE#198
- Isolate every core module in separate IIFE IITC-CE#234
- Move wrapper template to separate file IITC-CE#238
- DEFAULT_ZOOM = 15 (to match stock intel) IITC-CE#281
- IITC-CE#229:
  - Refactor build system into several modules (can be used as cli utilities).
    Implement `watch` mode to auto-rebuild on source changes.
  - Escape macros in code in order to keep js-validity, fix IITC-CE#50.
    Use template from settings instead of url harcoding (closes IITC-CE#150).
  - Simplify userscripts source template, rename plugin sources:  `*.user.js` -> `*.js`, rearrange source directories.
  - Remove timestamp component from `version` of Release scripts (closes IITC-CE#99).
  - Additional dev tools: `web_meta_gen.py`, `web_server_local.py`, `tampermonkey_stubs_gen.py`.
- Other
  - see IITC-CE#134 (solve IITC-CE#70: Manage upstream externals)
  - Update docs IITC-CE#264, remove outdated (info transferred to [wiki](https://github.com/IITC-CE/ingress-intel-total-conversion/wiki))

- Improve scale-bar and scoreboard plugins IITC-CE#158
- Improve styles of text labels (portal-level-numbers, portal-names, portal-names, regions, keys-on-map) IITC-CE#104
- Other
  - draw-tools, bookmarks: (make use of IITC-CE#243) support file import/export on desktop too
  - see IITC-CE#134: significantly enhance several plugins : overlay-kml, minimap, basemap-bing, basemap-yandex, tidy-links, pan-control, etc (see commit messages)

- sync: fix and update IITC-CE#212
- draw-tools: fix mobile-related bugs; add Circle again IITC-CE#175
- bookmarks: fix iitc download url IITC-CE#150
- portals-list: filter out portal without real data (bug in intel) IITC-CE#265
- Other: see IITC-CE#157 (cache-portals-on-map, layer-count, draw-tools, bookmarks, missions)

- 'Support DeX desktop mode' option IITC-CE#161
- Add 'Plugins' shortcut to main menu IITC-CE#266

- fix bugs on login page IITC-CE#164
- fix some bugs in plugins handling IITC-CE#245
- fix 'Send screenshot' function IITC-CE#169
- fix error that made it difficult to pick plugin file IITC-CE#239
- fix plugin initialization bug IITC-CE#270

- better handling of uploads IITC-CE#250
johnd0e added a commit to johnd0e/ingress-intel-total-conversion that referenced this pull request Dec 5, 2019
# Release notes

## IITC main script

### enhancements
- Update most upstream sources, and significantly enhance several plugins IITC-CE#134 (a lot of changes, follow the link to see)
- Fix performance drop when displaying a large number of ornaments IITC-CE#181
- Improve RegionScoreboard IITC-CE#179 © McBen + some fixes
- Remove confusing message from artifacts dialog IITC-CE#216
- Portal info: display coordinates without angled brackets IITC-CE#233
- Leaflet controls: prevent mobile style on desktop IITC-CE#189
- Increase map renderer padding (and make value customizable) IITC-CE#201
- Portal info: `shielding` tooltip: round mitigation `excess` to cope with lack of js float precision IITC-CE#279

### bugfixes
- Fix miscellaneous bugs in core and plugins IITC-CE#157
- Change default intel url (to match stock) IITC-CE#267

### development
- Implement plugins priority control IITC-CE#205
- Stop console 'spam' using customizable logger IITC-CE#235
- Consistent errors throwing IITC-CE#248
- API for local files (up|down)loading IITC-CE#243
- Remove some unused stuff from window object IITC-CE#101
- Refactor to use common function `window.makePermalink` (utils_misc.js) IITC-CE#198
- Isolate every core module in separate IIFE IITC-CE#234
- Move wrapper template to separate file IITC-CE#238
- DEFAULT_ZOOM = 15 (to match stock intel) IITC-CE#281
- IITC-CE#229:
  - Refactor build system into several modules (can be used as cli utilities).
    Implement `watch` mode to auto-rebuild on source changes.
  - Escape macros in code in order to keep js-validity, fix IITC-CE#50.
    Use template from settings instead of url harcoding (closes IITC-CE#150).
  - Simplify userscripts source template, rename plugin sources:  `*.user.js` -> `*.js`, rearrange source directories.
  - Remove timestamp component from `version` of Release scripts (closes IITC-CE#99).
  - Additional dev tools: `web_meta_gen.py`, `web_server_local.py`, `tampermonkey_stubs_gen.py`.
- Other
  - see IITC-CE#134 (solve IITC-CE#70: Manage upstream externals)
  - Update docs IITC-CE#264, remove outdated (info transferred to [wiki](https://github.com/IITC-CE/ingress-intel-total-conversion/wiki))

## Plugins

### enhancements
- Improve scale-bar and scoreboard plugins IITC-CE#158
- Improve styles of text labels (portal-level-numbers, portal-names, portal-names, regions, keys-on-map) IITC-CE#104
- Other
  - draw-tools, bookmarks: (make use of IITC-CE#243) support file import/export on desktop too
  - see IITC-CE#134: significantly enhance several plugins : overlay-kml, minimap, basemap-bing, basemap-yandex, tidy-links, pan-control, etc (see commit messages)

### bugfixes
- sync: fix and update IITC-CE#212
- draw-tools: fix mobile-related bugs; add Circle again IITC-CE#175
- bookmarks: fix iitc download url IITC-CE#150
- portals-list: filter out portal without real data (bug in intel) IITC-CE#265
- Other: see IITC-CE#157 (cache-portals-on-map, layer-count, draw-tools, bookmarks, missions)

## IITC-Mobile app

### enhancements
- 'Support DeX desktop mode' option IITC-CE#161
- Add 'Plugins' shortcut to main menu IITC-CE#266

### bugfixes
- fix bugs on login page IITC-CE#164
- fix some bugs in plugins handling IITC-CE#245
- fix 'Send screenshot' function IITC-CE#169
- fix error that made it difficult to pick plugin file IITC-CE#239
- fix plugin initialization bug IITC-CE#270

### development
- better handling of uploads IITC-CE#250
@johnd0e johnd0e mentioned this pull request Dec 5, 2019
johnd0e added a commit that referenced this pull request Dec 7, 2019
bump version to 0.30

# Release notes

## IITC main script

### enhancements
- Update most upstream sources, and significantly enhance several plugins #134 (a lot of changes, follow the link to see)
- Fix performance drop when displaying a large number of ornaments #181
- Improve RegionScoreboard #179 © McBen + some fixes
- Remove confusing message from artifacts dialog #216
- Portal info: display coordinates without angled brackets #233
- Leaflet controls: prevent mobile style on desktop #189
- Increase map renderer padding (and make value customizable) #201
- Portal info: `shielding` tooltip: round mitigation `excess` to cope with lack of js float precision #279

### bugfixes
- Fix miscellaneous bugs in core and plugins #157
- Change default intel url (to match stock) #267

### development
- Implement plugins priority control #205
- Stop console 'spam' using customizable logger #235
- Consistent errors throwing #248
- API for local files (up|down)loading #243
- Remove some unused stuff from window object #101
- Refactor to use common function `window.makePermalink` (utils_misc.js) #198
- Isolate every core module in separate IIFE #234
- Move wrapper template to separate file #238
- DEFAULT_ZOOM = 15 (to match stock intel) #281
- #229:
  - Refactor build system into several modules (can be used as cli utilities).
    Implement `watch` mode to auto-rebuild on source changes.
  - Escape macros in code in order to keep js-validity, fix #50.
    Use template from settings instead of url harcoding (closes #150).
  - Simplify userscripts source template, rename plugin sources:  `*.user.js` -> `*.js`, rearrange source directories.
  - Remove timestamp component from `version` of Release scripts (closes #99).
  - Additional dev tools: `web_meta_gen.py`, `web_server_local.py`, `tampermonkey_stubs_gen.py`.
- Other
  - see #134 (solve #70: Manage upstream externals)
  - Update docs #264, remove outdated (info transferred to [wiki](https://github.com/IITC-CE/ingress-intel-total-conversion/wiki))

## Plugins

### enhancements
- Improve scale-bar and scoreboard plugins #158
- Improve styles of text labels (portal-level-numbers, portal-names, portal-names, regions, keys-on-map) #104
- Other
  - draw-tools, bookmarks: (make use of #243) support file import/export on desktop too
  - see #134: significantly enhance several plugins : overlay-kml, minimap, basemap-bing, basemap-yandex, tidy-links, pan-control, etc (see commit messages)

### bugfixes
- sync: fix and update #212
- draw-tools: fix mobile-related bugs; add Circle again #175
- bookmarks: fix iitc download url #150
- portals-list: filter out portal without real data (bug in intel) #265
- Other: see #157 (cache-portals-on-map, layer-count, draw-tools, bookmarks, missions)

## IITC-Mobile app

### enhancements
- 'Support DeX desktop mode' option #161
- Add 'Plugins' shortcut to main menu #266
- Adapt to changes in Google authorization #283

### bugfixes
- fix bugs on login page #164
- fix some bugs in plugins handling #245
- fix 'Send screenshot' function #169
- fix error that made it difficult to pick plugin file #239
- fix plugin initialization bug #270

### development
- better handling of uploads #250
@modos189 modos189 moved this from Merged to Old release in Track features for next release Dec 22, 2019
@modos189 modos189 moved this from Old release to Merged in Track features for next release Dec 22, 2019
@johnd0e johnd0e mentioned this pull request Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core development general development issue enhancement New feature or request plugin
Development

Successfully merging this pull request may close these issues.

None yet

3 participants