From b17b04eb0f489c052629fa025d8efc23a9a9b792 Mon Sep 17 00:00:00 2001 From: Paul Date: Mon, 22 Aug 2022 14:31:44 +0100 Subject: [PATCH] Version 2.1 --- api/gun_api.py | 17 ++-- app.yaml | 4 +- bcp.code-workspace | 2 +- bcp/angular.json | 4 +- .../bcp-record-observer.component.html | 81 ++++++++++++++----- .../bcp-record-observer.component.ts | 24 ++++-- .../bcp-site-selector.component.ts | 10 +-- bcp/src/app/bcp-v2/bcp-v2.component.html | 46 ++++++----- bcp/src/manifest.json | 2 +- main.py | 10 ++- site_script.py | 2 +- site_update.py | 4 +- 12 files changed, 136 insertions(+), 70 deletions(-) diff --git a/api/gun_api.py b/api/gun_api.py index 1997ded..d18e13c 100644 --- a/api/gun_api.py +++ b/api/gun_api.py @@ -85,15 +85,16 @@ def set_record(user, body): gunid=gun_id, name=user.email, ) + new_site = Site.get_by_id(to_int(body.get("site_id", "")),namespace=namespace) if to_int(body.get("site_id", "")) != gun.site_id: - old_site = Site.get_by_id(gun.site_id, namespace=namespace) - new_site = Site.get_by_id(to_int(body.get("site_id", "")),namespace=namespace) - old_site.guns.remove(gun.gunid) + if not gun.site_id is None: + old_site = Site.get_by_id(gun.site_id, namespace=namespace) + old_site.guns.remove(gun.gunid) + if len(old_site.guns) < 1: + old_site.key.delete() + else: + old_site.put() new_site.guns.append(gun.gunid) - if len(old_site.guns) < 1: - old_site.key.delete() - else: - old_site.put() new_site.put() gun.populate( description=body.get('description', ""), @@ -131,7 +132,7 @@ def set_record(user, body): gun.measurements = m gun.put() return {"gun": gun.api_data(users, True), - "sites": [old_site.api_data(), new_site.api_data()] + "sites": [new_site.api_data() if old_site is None else old_site.api_data() , new_site.api_data()] },(200) except Exception as e: try: diff --git a/app.yaml b/app.yaml index a1ec380..7dabbce 100644 --- a/app.yaml +++ b/app.yaml @@ -1,9 +1,9 @@ runtime: python39 instance_class: F4 -service: stageing +service: default automatic_scaling: min_instances: 0 -entrypoint: gunicorn -b :8080 -w 1 main:app +entrypoint: gunicorn -b :$PORT -w 4 main:app handlers: - url: /_ah/api/.* diff --git a/bcp.code-workspace b/bcp.code-workspace index 362d7c2..2a0ed79 100644 --- a/bcp.code-workspace +++ b/bcp.code-workspace @@ -1,7 +1,7 @@ { "folders": [ { - "path": "." + "path": ".." } ] } \ No newline at end of file diff --git a/bcp/angular.json b/bcp/angular.json index 25da41a..c409aaa 100644 --- a/bcp/angular.json +++ b/bcp/angular.json @@ -53,7 +53,7 @@ "budgets": [ { "type": "initial", - "maximumWarning": "2mb", + "maximumWarning": "3mb", "maximumError": "5mb" }, { @@ -80,7 +80,7 @@ "budgets": [ { "type": "initial", - "maximumWarning": "2mb", + "maximumWarning": "3mb", "maximumError": "5mb" }, { diff --git a/bcp/src/app/bcp-record-observer/bcp-record-observer.component.html b/bcp/src/app/bcp-record-observer/bcp-record-observer.component.html index 014cec4..1e4f619 100644 --- a/bcp/src/app/bcp-record-observer/bcp-record-observer.component.html +++ b/bcp/src/app/bcp-record-observer/bcp-record-observer.component.html @@ -180,7 +180,7 @@ -
+
@@ -202,33 +202,70 @@ - - Google Page - - Website - - + Google + + Website + + + + + + + + Google Page + + Website + + + + -import { Component, OnInit, Input, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core'; +import { Component, OnInit, Input, OnDestroy, ViewChild, ChangeDetectorRef, ElementRef, HostListener } from '@angular/core'; import { UntypedFormGroup } from '@angular/forms'; import { DataItem } from '../bcp-map-data.service'; import { Site, BcpSiteDataService } from '../bcp-site-data.service'; @@ -20,12 +20,19 @@ export class BcpRecordObserverComponent implements OnInit, OnDestroy { private _gun: DataItem @ViewChild(BcpPhotosComponent) photo: BcpPhotosComponent; + private _siteCardElement: ElementRef; + @ViewChild("site_card", {static: false}) + set siteCardElement(el: ElementRef) { + this._siteCardElement = el; + this.collapsed = this._siteCardElement?.nativeElement.offsetWidth < 350 + } @Input() gunForm: UntypedFormGroup; edit: boolean; editAttribution: boolean = false; + collapsed: boolean = false; @Input() set gun(value: DataItem) { @@ -143,10 +150,12 @@ export class BcpRecordObserverComponent implements OnInit, OnDestroy { siteChanged(site: Site) { if (this.edit && site) { const old_site= this.sites.fetch(this.gun.site_id); - old_site.guns = old_site.guns.filter(item => item != this.gun.gunid) - if (old_site.guns.length < 1) { - this.sites.remove(site) - }; + if (old_site) { + old_site.guns = old_site.guns.filter(item => item != this.gun.gunid) + if (old_site.guns.length < 1) { + this.sites.remove(site) + }; + } if (! site.id) { let data = { source: "Google", @@ -177,4 +186,9 @@ export class BcpRecordObserverComponent implements OnInit, OnDestroy { if (this.currentUser && this.currentUser.test_user) folderName = "dev"; this.photo.send_file(`/${folderName}/${this.gun.gunid}`, this.gun.gunid) } + + @HostListener('window:resize', ['$event']) + onWindowResize() { + this.collapsed = this._siteCardElement?.nativeElement.offsetWidth < 350 + } } diff --git a/bcp/src/app/bcp-site-selector/bcp-site-selector.component.ts b/bcp/src/app/bcp-site-selector/bcp-site-selector.component.ts index 0c36f9a..12a73f1 100644 --- a/bcp/src/app/bcp-site-selector/bcp-site-selector.component.ts +++ b/bcp/src/app/bcp-site-selector/bcp-site-selector.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, Input, ChangeDetectorRef, Output, EventEmitter } from '@angular/core'; +import { Component, OnInit, OnDestroy, Input, ChangeDetectorRef, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core'; import { Site, BcpSiteDataService } from '../bcp-site-data.service'; import { BcpUserService } from '../bcp-user.service'; import { BcpApiService } from '../bcp-api.service'; @@ -87,16 +87,16 @@ export class BcpSiteSelectorComponent implements OnInit, OnDestroy { for (let geocode of data) { let site = Site.fromGeocode(geocode); if (site.geocode.geometry.viewport.contains(this.location)) { - this.candidateSites.push([site, + this.candidateSites = [...this.candidateSites, + [site, google.maps.geometry.spherical.computeDistanceBetween( this.location, site.geocode.geometry.location - ) - ]); + )] + ]; } } } this.candidateSites.sort( (a,b) => a[1] - b[1]); - this.changDetect.detectChanges(); } private showError(error) { switch (error.code) { diff --git a/bcp/src/app/bcp-v2/bcp-v2.component.html b/bcp/src/app/bcp-v2/bcp-v2.component.html index 3cd6c49..f22f4b5 100644 --- a/bcp/src/app/bcp-v2/bcp-v2.component.html +++ b/bcp/src/app/bcp-v2/bcp-v2.component.html @@ -1,24 +1,15 @@
-

Version 2

-

Version 2 is currently in BETA - not everything will work!

+

Version 2

Version 2 is a completely new version of the application using the latest techniques. This provides a platform for the future of this application.

This version of the application uses the same database and users as - the current version. This means: + the previous version.

-
    -
  • - that you see the same guns in version 2 as you see in version 1, and -
  • -
  • - IMPORTANT - that if you make changes in version 2 they will change the real database. -
  • -

Please do not "experiment" with the data using your real login. If you want to experiment, there is a training login that you can use for that :

@@ -34,25 +25,40 @@

Version 2

-

Changes

-

- The basic "flow" of the application is not changed. Most things work in the same way. The following are some of the changes: -

+

Changes

+

For more details see here

    +
  • + One of the biggest changes in the new version is that the main view of the database is by Site. + +
  • +
  • + By default, the list of Sites (and the List of Guns) is filtered just to show the Sites ( or Guns) that are currently visible on the map. + This feature can be turned off, by flicking the slider switch marked “Here” whereupon it will read “All”. +
  • +
  • + To make the application startup faster and more responsive we are now doing incremental loads of data.What does this mean for you? Mostly, this means that when you first open the application you will see the number of guns shown on the map count upwards for a few seconds as the data is loaded and it might take as longer as 30 seconds before the record you are interested in is loaded. +
  • +
  • + The new record process has been streamlined a bit. + A good workflow when adding a new Gun to an existing Site (or adding multiple guns to a site) is to open the Site and use the “Add Gun” Button which will prepopulate the record. + You can also now add a link to an existing image or an existing web page, without needing to upload the images. This saves data, saves time and saves us storage costs. +
  • +
  • + Tools to make it easier to analysis the database contents are working and will be released soon. +
  • +
  • The "login" menu item is now an icon on the right of the toolar with a picture of a person. This will eventually show a profile picture and a user profile. The login screen does nt require popups anymore
  • -
  • - The "new Record" Dialog has been rewritten to make it more usuable and does not require a popup anymore. -
  • British National Grid references have been removed since they do not seem to be used.
  • The default order of the database has been changed to show the most recently entered records first.
  • - We are adding some new seaerch filters. The only one that is currently working is to show only the records that you have created. + We are adding some new seaerch filters, including to show only the records that you have created.
  • We are changing the order the "tabs" in the Gun details screens to more naturally mtch the way that people add data. @@ -62,7 +68,7 @@

    Changes

-

Contributing

+

Contributing

Version 2 desperately needs more coders!

We really do need more help to make Version 2 work and add the community features and researcher features that we want to create.

If you would like to help out, whether coding or create better "help" and "best practice" screens or if you are a researcher diff --git a/bcp/src/manifest.json b/bcp/src/manifest.json index 9c5c957..a561a73 100644 --- a/bcp/src/manifest.json +++ b/bcp/src/manifest.json @@ -15,7 +15,7 @@ ], "start_url": "/", "background_color": "#e3f2fd", - "display": "standalone", + "display": "fullscreen", "scope": "/", "theme_color": "#e3f2fd" } diff --git a/main.py b/main.py index 5f308b6..10d22ae 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,14 @@ import logging from google.cloud import ndb +try: + import googleclouddebugger + googleclouddebugger.enable( + breakpoint_enable_canary=True + ) +except ImportError: + pass + firebase_admin.initialize_app() client = ndb.Client() @@ -35,7 +43,7 @@ app.add_api('openapi.yaml', strict_validation=True) # add CORS support CORS(app.app) -logging.getLogger('flask_cors').level = logging.DEBUG +logging.getLogger('flask_cors').level = logging.ERROR if __name__ == '__main__': # This is used when running locally only. When deploying to Google App diff --git a/site_script.py b/site_script.py index a3ec1f9..8f72a71 100644 --- a/site_script.py +++ b/site_script.py @@ -1,4 +1,3 @@ -from argparse import Namespace from data import Site from google.cloud import ndb import googlemaps @@ -63,6 +62,7 @@ class Categories(Enum): geocode = ndb.JsonProperty() site = ndb.StringProperty() display_name = ndb.StringProperty() + geocode = ndb.JsonProperty() with client.context(): sites = Site.query(namespace= namespace).fetch() diff --git a/site_update.py b/site_update.py index 417f8c7..eb23ee7 100644 --- a/site_update.py +++ b/site_update.py @@ -95,6 +95,6 @@ def deleteGuns(): gun.key.delete() -#Update.updateSites() -#Update.setGuns() +Update.updateSites() +Update.setGuns() Update.deleteGuns()