From 5a9182bdec1da0a32e210ba2e6fe8be177be52aa Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Sat, 19 May 2018 16:49:06 -0700 Subject: [PATCH 1/6] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 249b9eb..38e970c 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ A generalized Flask application for displaying location-based resources on a map ## Setting up +If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools. In my OS (Winows 10), I can then run "bash" to open the window in which to run the instructions below. + ##### Clone the repo ``` From 33479faba7c4a0926c2a201c9bf68b40110a6d62 Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Sat, 19 May 2018 17:56:11 -0700 Subject: [PATCH 2/6] Tracking my solutions. --- README.md | 150 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 38e970c..05d80a0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Maps4All [![Circle CI](https://circleci.com/gh/hack4impact/maps4all.svg?style=svg)](https://circleci.com/gh/hack4impact/maps4all) [![Code Climate](https://codeclimate.com/github/hack4impact/maps4all/badges/gpa.svg)](https://codeclimate.com/github/hack4impact/maps4all) [![Test Coverage](https://codeclimate.com/github/hack4impact/maps4all/badges/coverage.svg)](https://codeclimate.com/github/hack4impact/maps4all/coverage) [![Issue Count](https://codeclimate.com/github/hack4impact/maps4all/badges/issue_count.svg)](https://codeclimate.com/github/hack4impact/maps4all) +# Maps4All [![Circle CI](https://circleci.com/gh/hack4impact/maps4all.svg?style=svg)](https://circleci.com/gh/hack4impact/maps4all) [![Code Climate](https://codeclimate.com/github/hack4impact/maps4all/badges/gpa.svg)](https://codeclimate.com/github/hack4impact/maps4all) [![Test Coverage](https://codeclimate.com/github/hack4impact/maps4all/badges/coverage.svg)](https://codeclimate.com/github/hack4impact/maps4all/coverage) [![Issue Count](https://codeclimate.com/github/hack4impact/maps4all/badges/issue_count.svg)](https://codeclimate.com/github/hack4impact/maps4all) ## Team Members @@ -34,6 +34,12 @@ $ cd maps4all ##### Initialize a virtualenv +virtualenv does not properly handle spaces in filenames, but it will dereference hardlinks. This created a problem for me in that it failed silently and did not create the venv folder. I got around this problem by using the full path (that has no spaces in it) to python3 at %USERPROFILE%\AppData\Local\Programs\Python\Python36-32\python.exe. However, I still ran into: + ERROR: The executable C:\Users\dscot\github\maps4all\venv\Scripts\python.exe is not functioning + ERROR: It thinks sys.prefix is 'c:\\users\\dscot\\github\\maps4all' (should be 'c:\\users\\dscot\\github\\maps4all\\venv') + ERROR: virtualenv is not compatible with this system or executable + Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versions of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem. + ``` $ pip install virtualenv $ virtualenv -p python3 venv @@ -136,77 +142,77 @@ Then navigate to `http://localhost:5000` on your preferred browser to open the w ``` -├── Procfile -├── README.md -├── app -│   ├── __init__.py -│   ├── account -│   │   ├── __init__.py -│   │   ├── forms.py -│   │   └── views.py -│   ├── admin -│   │   ├── __init__.py -│   │   ├── forms.py -│   │   └── views.py -│   ├── assets -│   │   ├── scripts -│   │   │   ├── app.js -│   │   │   └── vendor -│   │   │   ├── jquery.min.js -│   │   │   ├── semantic.min.js -│   │   │   └── tablesort.min.js -│   │   └── styles -│   │   ├── app.scss -│   │   └── vendor -│   │   └── semantic.min.css -│   ├── assets.py -│   ├── decorators.py -│   ├── email.py -│   ├── main -│   │   ├── __init__.py -│   │   ├── errors.py -│   │   ├── forms.py -│   │   └── views.py -│   ├── models.py -│   ├── static -│   │   ├── fonts -│   │   │   └── vendor -│   │   ├── images -│   │   └── styles -│   │      └── app.css -│   ├── templates -│   │   ├── account -│   │   │   ├── email -│   │   │   ├── login.html -│   │   │   ├── manage.html -│   │   │   ├── register.html -│   │   │   ├── reset_password.html -│   │   │   └── unconfirmed.html -│   │   ├── admin -│   │   │   ├── index.html -│   │   │   ├── manage_user.html -│   │   │   ├── new_user.html -│   │   │   └── registered_users.html -│   │   ├── errors -│   │   ├── layouts -│   │   │   └── base.html -│   │   ├── macros -│   │   │   ├── form_macros.html -│   │   │   └── nav_macros.html -│   │   ├── main -│   │   │   └── index.html -│   │   └── partials -│   │   ├── _flashes.html -│   │   └── _head.html -│   └── utils.py -├── config.py -├── manage.py -├── requirements -│   ├── common.txt -│   └── dev.txt -└── tests - ├── test_basics.py - └── test_user_model.py +??? Procfile +??? README.md +??? app +?   ??? __init__.py +?   ??? account +?   ?   ??? __init__.py +?   ?   ??? forms.py +?   ?   ??? views.py +?   ??? admin +?   ?   ??? __init__.py +?   ?   ??? forms.py +?   ?   ??? views.py +?   ??? assets +?   ?   ??? scripts +?   ?   ?   ??? app.js +?   ?   ?   ??? vendor +?   ?   ?   ??? jquery.min.js +?   ?   ?   ??? semantic.min.js +?   ?   ?   ??? tablesort.min.js +?   ?   ??? styles +?   ?   ??? app.scss +?   ?   ??? vendor +?   ?   ??? semantic.min.css +?   ??? assets.py +?   ??? decorators.py +?   ??? email.py +?   ??? main +?   ?   ??? __init__.py +?   ?   ??? errors.py +?   ?   ??? forms.py +?   ?   ??? views.py +?   ??? models.py +?   ??? static +?   ?   ??? fonts +?   ?   ?   ??? vendor +?   ?   ??? images +?   ?   ??? styles +?   ?      ??? app.css +?   ??? templates +?   ?   ??? account +?   ?   ?   ??? email +?   ?   ?   ??? login.html +?   ?   ?   ??? manage.html +?   ?   ?   ??? register.html +?   ?   ?   ??? reset_password.html +?   ?   ?   ??? unconfirmed.html +?   ?   ??? admin +?   ?   ?   ??? index.html +?   ?   ?   ??? manage_user.html +?   ?   ?   ??? new_user.html +?   ?   ?   ??? registered_users.html +?   ?   ??? errors +?   ?   ??? layouts +?   ?   ?   ??? base.html +?   ?   ??? macros +?   ?   ?   ??? form_macros.html +?   ?   ?   ??? nav_macros.html +?   ?   ??? main +?   ?   ?   ??? index.html +?   ?   ??? partials +?   ?   ??? _flashes.html +?   ?   ??? _head.html +?   ??? utils.py +??? config.py +??? manage.py +??? requirements +?   ??? common.txt +?   ??? dev.txt +??? tests + ??? test_basics.py + ??? test_user_model.py ``` ## License From 4b00577f44aff7f2cdc74e3b3303b1c26d0f7802 Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Wed, 23 May 2018 14:11:37 -0700 Subject: [PATCH 3/6] Finalized how I started development on Windows 10 --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 05d80a0..8d61c0d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ A generalized Flask application for displaying location-based resources on a map ## Setting up -If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools. In my OS (Winows 10), I can then run "bash" to open the window in which to run the instructions below. +If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools. To develop locally on Windows 10, we (@sbue and myself, independently) used Windows Subsystem for Linux and additionally installed Heroku CLI in Ubuntu terminal and deployed with the client. ##### Clone the repo @@ -33,12 +33,6 @@ $ cd maps4all ``` ##### Initialize a virtualenv - -virtualenv does not properly handle spaces in filenames, but it will dereference hardlinks. This created a problem for me in that it failed silently and did not create the venv folder. I got around this problem by using the full path (that has no spaces in it) to python3 at %USERPROFILE%\AppData\Local\Programs\Python\Python36-32\python.exe. However, I still ran into: - ERROR: The executable C:\Users\dscot\github\maps4all\venv\Scripts\python.exe is not functioning - ERROR: It thinks sys.prefix is 'c:\\users\\dscot\\github\\maps4all' (should be 'c:\\users\\dscot\\github\\maps4all\\venv') - ERROR: virtualenv is not compatible with this system or executable - Note: some Windows users have reported this error when they installed Python for "Only this user" or have multiple versions of Python installed. Copying the appropriate PythonXX.dll to the virtualenv Scripts/ directory may fix this problem. ``` $ pip install virtualenv From c1e6c76f7f457bfb0375d90a0136b14d2c170d13 Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Sat, 23 Jun 2018 21:02:59 -0700 Subject: [PATCH 4/6] Added code to allow admin to add a Javascript file that runs after all other javascript in the has already been loaded. No tests have been added. --- README.md | 10 +++++++++- app/admin/views.py | 22 ++++++++++++++++++++++ app/templates/admin/customize_site.html | 22 ++++++++++++++++++++++ app/templates/partials/_head.html | 3 +++ app/utils.py | 3 ++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d61c0d..cb4734a 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,15 @@ A generalized Flask application for displaying location-based resources on a map ## Setting up -If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools. To develop locally on Windows 10, we (@sbue and myself, independently) used Windows Subsystem for Linux and additionally installed Heroku CLI in Ubuntu terminal and deployed with the client. +If you have not yet done so, visit maps4all.org and create an account. This will guide you through the creation of your Heroku account and the installation of the Heroku tools. + +### Windows 10 + +To develop locally on Windows 10, we (@sbue and myself, independently) used Windows Subsystem for Linux and additionally installed Heroku CLI in Ubuntu terminal and deployed with the client. This runs the app on Heroku servers, but you can run it locally too. + +#### Editing local files + +Check https://superuser.com/questions/1083962/windows-linux-subsystem-accessing-files-outside-of-ubuntu to see how you can deal with the fact that Windows' "subsystem for Linux" doesn't work very well when you edit files the Linux subsystem will use directly from Windows. It's best to go through the bash shell to create or edit files. ##### Clone the repo diff --git a/app/admin/views.py b/app/admin/views.py index 31f05c4..9cc3543 100644 --- a/app/admin/views.py +++ b/app/admin/views.py @@ -346,6 +346,28 @@ def change_site_style(): app_name=SiteAttribute.get_value("ORG_NAME")) +@admin.route('/customize-site/script', methods=['GET', 'POST']) +@login_required +@admin_required +def add_javascript(): + """Add to a site's javascript.""" + if request.method == 'POST': + script_attr = SiteAttribute.get("EXTRA_SCRIPT") + + url = request.form['url'] + script_attr.value = url + + db.session.add(script_attr) + db.session.commit() + + flash('Custom javascript successfully uploaded or replaced.') + + return redirect(url_for('admin.customize_site')) + + return render_template('admin/customize_site.html', + app_name=SiteAttribute.get_value("ORG_NAME")) + + @admin.route('/customize-site/twilio', methods=['GET', 'POST']) @login_required def change_twilio_credentials(): diff --git a/app/templates/admin/customize_site.html b/app/templates/admin/customize_site.html index 8a3d36c..55b1c67 100644 --- a/app/templates/admin/customize_site.html +++ b/app/templates/admin/customize_site.html @@ -7,6 +7,7 @@ ('admin.change_site_logo', 'Change logo'), ('admin.change_site_style', 'Change style'), ('admin.change_twilio_credentials', 'Change Twilio credentials'), + ('admin.add_javascript', 'Add Javascript'), ] %} {% macro navigation(items) %} @@ -49,6 +50,11 @@

Upload + {% elif request.endpoint == 'admin.add_javascript' %} + {% else %} @@ -120,6 +126,22 @@

} }); } + + function openPickerScript() { + fsClient.pick({ + fromSources:["local_file_system","googledrive","dropbox"], + maxFiles:1, + minFiles:1, + accept:[".js"], + startUploadingWhenMaxFilesReached: true, + }).then(function(response) { + if (response.filesFailed.length != 0) { + alert("An error occurred. Please share this with the developer: " + JSON.stringify(response)); + } else { + post("{{ url_for('admin.add_javascript') }}", {'url': response.filesUploaded[0].url}); + } + }); + } {% endblock %} diff --git a/app/templates/partials/_head.html b/app/templates/partials/_head.html index 49da996..df6e154 100644 --- a/app/templates/partials/_head.html +++ b/app/templates/partials/_head.html @@ -19,6 +19,9 @@ {% assets 'vendor_js' %}{% endassets %} {% assets 'app_js' %}{% endassets %} + + + diff --git a/app/utils.py b/app/utils.py index f12f3fe..f9ec8ed 100644 --- a/app/utils.py +++ b/app/utils.py @@ -22,7 +22,8 @@ def inject_name(): return dict(site_name=SiteAttribute.get_value("ORG_NAME"), logo_url=SiteAttribute.get_value("SITE_LOGO"), style_timestamp=SiteAttribute.get_value("STYLE_TIME"), - style_sheet=SiteAttribute.get_value("STYLE_SHEET")) + style_sheet=SiteAttribute.get_value("STYLE_SHEET"), + extra_script=SiteAttribute.get_value("EXTRA_SCRIPT")) app.add_template_global(index_for_role) From f05b1f23dd6be2d56de8e33144ab97814a581cf3 Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Sun, 1 Jul 2018 12:00:56 -0700 Subject: [PATCH 5/6] Fixed bug preventing options fields from showing. In Firefox 60.0.2 (64-bit), selecting the descriptor type "Option" did not cause option entry fields to be displayed. I used the console to show the hidden (by default) div and was then able to create an options descriptor. This commit is so that Heroku will pick up the change I believe will allow us to create descriptors of type "Option." --- app/assets/scripts/descriptor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/scripts/descriptor.js b/app/assets/scripts/descriptor.js index 1e7c9fd..645cf4e 100644 --- a/app/assets/scripts/descriptor.js +++ b/app/assets/scripts/descriptor.js @@ -27,7 +27,7 @@ $(document).ready(function () { // This is for the new descriptor page $("#desc_type").change(function() { - if ($(this).val() === "Option") { + if ($(this).val() === "option") { $("#values-div").show(); } else { $("#values-div").hide(); From a63ad3141aeb5ece9eade11c60cacf82570ee519 Mon Sep 17 00:00:00 2001 From: Dave Scotese Date: Mon, 1 Oct 2018 19:52:15 -0700 Subject: [PATCH 6/6] Hardcoded our APIKey. Dangerous, I know, but we can just shut it and fix it later if it gets ugly. It's a free Filestack account right now. --- config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.py b/config.py index 39ca975..1a769b1 100644 --- a/config.py +++ b/config.py @@ -34,7 +34,7 @@ class Config: RQ_DEFAULT_PASSWORD = url.password RQ_DEFAULT_DB = 0 - FILEPICKER_API_KEY = os.environ.get('FILEPICKER_API_KEY') + FILEPICKER_API_KEY = 'A3vAepVXiRleXVywQ8fkRzin' or os.environ.get('FILEPICKER_API_KEY') @staticmethod def init_app(app):

Name{{ app_name }}