Skip to content

Commit

Permalink
Version 2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
runette committed Aug 22, 2022
1 parent 1d96b9a commit b17b04e
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 70 deletions.
17 changes: 9 additions & 8 deletions api/gun_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ""),
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -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/.*
Expand Down
2 changes: 1 addition & 1 deletion bcp.code-workspace
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"folders": [
{
"path": "."
"path": ".."
}
]
}
4 changes: 2 additions & 2 deletions bcp/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumWarning": "3mb",
"maximumError": "5mb"
},
{
Expand All @@ -80,7 +80,7 @@
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumWarning": "3mb",
"maximumError": "5mb"
},
{
Expand Down
81 changes: 59 additions & 22 deletions bcp/src/app/bcp-record-observer/bcp-record-observer.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
</mat-card-content>
</mat-card>
</div>
<div class="col-sm-6">
<div class="col-sm-6" #site_card>
<!-- Site Details-->
<mat-card *ngIf="site">
<mat-card-title-group>
Expand All @@ -202,33 +202,70 @@
</mat-chip-list>
</mat-card-content>
<mat-card-actions align="end">
<button mat-raised-button color="primary"
*ngIf="user.login"
<button mat-raised-button color="primary"
*ngIf="user.login && ! collapsed"
[routerLink]="['/database/site']"
[queryParams]="{site_id:site.id}"
matTooltip="Goto the Details Page for this Site"
>Goto Site
</button>
<a mat-raised-button color="primary"
*ngIf="site.type=='google' && user.login"
[href]="site.geocode.url"
target="_blank"
matTooltip="Goto the Google page for this site"
>Google Page
</a>
<a mat-raised-button color="primary"
*ngIf="site.geocode.website && user.login"
[href]="site.geocode.website"
target="_blank"
matTooltip="Goto the website for this site"
>Website
</a>
<button mat-raised-button
*ngIf="user.login && this.edit"
>Site
</button>
<a mat-raised-button color="primary"
*ngIf="site.type=='google' && user.login && ! collapsed"
[href]="site.geocode.url"
target="_blank"
matTooltip="Goto the Google page for this site"
>Google
</a>
<a mat-raised-button color="primary"
*ngIf="site.geocode.website && user.login && ! collapsed"
[href]="site.geocode.website"
target="_blank"
matTooltip="Goto the website for this site"
>Website
</a>
<button mat-raised-button
*ngIf="user.login && this.edit && ! collapsed"
color="primary"
(click)="site=null"
>Change
</button>
</button>
<button mat-raised-button
color="primary"
[mat-menu-trigger-for]="menu"
*ngIf="collapsed"
>
<mat-icon>menu</mat-icon>
</button>
<mat-menu x-position="before" #menu>
<mat-action-list>
<button mat-list-item
*ngIf="user.login"
[routerLink]="['/database/site']"
[queryParams]="{site_id:site.id}"
matTooltip="Goto the Details Page for this Site"
>Goto Site
</button>
<a mat-list-item
*ngIf="site.type=='google' && user.login"
[href]="site.geocode.url"
target="_blank"
matTooltip="Goto the Google page for this site"
>Google Page
</a>
<a mat-list-item
*ngIf="site.geocode.website && user.login"
[href]="site.geocode.website"
target="_blank"
matTooltip="Goto the website for this site"
>Website
</a>
<button mat-list-item
*ngIf="user.login && this.edit"
(click)="site=null"
>Change
</button>
</mat-action-list>
</mat-menu>
</mat-card-actions>
</mat-card>
<app-bcp-site-selector *ngIf="! site"
Expand Down
24 changes: 19 additions & 5 deletions bcp/src/app/bcp-record-observer/bcp-record-observer.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///<reference types='google.maps' />
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';
Expand All @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
}
10 changes: 5 additions & 5 deletions bcp/src/app/bcp-site-selector/bcp-site-selector.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
46 changes: 26 additions & 20 deletions bcp/src/app/bcp-v2/bcp-v2.component.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<div class="container mt-5">
<div class="jumbotron jumbotron-fluid bg-white m-1">
<div class="container">
<h3 >Version 2</h3>
<p><strong> Version 2 is currently in BETA - not everything will work!</strong></p>
<h2 >Version 2</h2>
<p>
Version 2 is a completely new version of the application using the latest techniques.
This provides a platform for the future of this application.
</p>
<p>
This version of the application uses <strong>the same database and users</strong> as
the current version. This means:
the previous version.
</p>
<ul>
<li>
that you see the same guns in version 2 as you see in version 1, and
</li>
<li>
IMPORTANT - that if you make changes in version 2 they will change the real database.
</li>
</ul>
<p>
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 :
</p>
Expand All @@ -34,25 +25,40 @@ <h3 >Version 2</h3>
</div>
<div class="jumbotron jumbotron-fluid bg-white m-1">
<div class="container">
<h3 >Changes</h3>
<p>
The basic "flow" of the application is not changed. Most things work in the same way. The following are some of the changes:
</p>
<h2 >Changes</h2>
<h3>For more details see <a href="https://mailchi.mp/da94f4933140/big-cannon-project-going-from-strength-to-strength">here</a></h3>
<ul>
<li>
One of the biggest changes in the new version is that the main view of the database is by Site.

</li>
<li>
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”.
</li>
<li>
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.
</li>
<li>
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.
</li>
<li>
Tools to make it easier to analysis the database contents are working and will be released soon.
</li>

<li>
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
</li>
<li>
The "new Record" Dialog has been rewritten to make it more usuable and does not require a popup anymore.
</li>
<li>British National Grid references have been removed since they do not seem to be used.</li>
<li>
The default order of the database has been changed to show the most recently entered records first.
</li>
<li>
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.
</li>
<li>
We are changing the order the "tabs" in the Gun details screens to more naturally mtch the way that people add data.
Expand All @@ -62,7 +68,7 @@ <h3 >Changes</h3>
</div>
<div class="jumbotron jumbotron-fluid bg-white m-1">
<div class="container">
<h3 >Contributing</h3>
<h2 >Contributing</h2>
<p><strong>Version 2 desperately needs more coders!</strong></p>
<p> We really do need more help to make Version 2 work and add the community features and researcher features that we want to create.</p>
<p> If you would like to help out, whether coding or create better "help" and "best practice" screens or if you are a researcher
Expand Down
2 changes: 1 addition & 1 deletion bcp/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"start_url": "/",
"background_color": "#e3f2fd",
"display": "standalone",
"display": "fullscreen",
"scope": "/",
"theme_color": "#e3f2fd"
}
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion site_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from argparse import Namespace
from data import Site
from google.cloud import ndb
import googlemaps
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions site_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ def deleteGuns():
gun.key.delete()


#Update.updateSites()
#Update.setGuns()
Update.updateSites()
Update.setGuns()
Update.deleteGuns()

0 comments on commit b17b04e

Please sign in to comment.