Displaying differences for changeset
 
display as  

services.py

@@ -2668,14 +2668,22 @@
         self.assessments = []
         self.load_registry()
 
-    def GET(self):
-        """Add project to tracking registry"""
+#     def GET(self):
+#         """Load all 'tracking sheet' options for UI to pick from"""
+#         import pdb; pdb.set_trace()
+#         return er2_api.respond(self)
+
+    def get_selected_registry(self, selected_tracking_sheet):
+        """Fetch a particular tracking sheet"""
+
+
+#         import pdb; pdb.set_trace()
         for basin_data in self.registry["basins"]:
             for site in basin_data["sites"]:
                 self.assessments.append(site)
         return er2_api.respond(self)
 
-    def add_summary_to_registry(self, summary_arg):
+    def add_summary_to_tracking_sheet(self, selected_tracking_sheet, summary_arg):
         summary = summary_arg.copy()
         summary.update(
             {
@@ -2736,7 +2744,7 @@
         cache.set("__303D_assessment_registry", json.dumps(self.registry))
         jsondump(self._tracking_path, self.registry)
 
-    def remove_summary_from_registry(self, basin_name, token):
+    def remove_summary_from_tracking_sheet(self, selected_tracking_sheet, basin_name, token):
         # Locate the basin
         ibasins = [
             i for i, b in enumerate(self.registry["basins"]) if b["name"] == basin_name

static/er2_303d_assess/js/actions/assessment_summary.js

@@ -12,12 +12,13 @@
 export const addToRegistry = () => (dispatch, getState) => {
     let hasError = false
     const { summary } = getState().assessmentSummary
+    const selectedTrackingSheet = ""
     fetch(
-        `/${getState().meta.name}/api/v1/add_to_assessment_registry/?token=${
+        `/${getState().meta.name}/api/v1/add_to_tracking_sheet/?token=${
             getState().token.value
         }`,
         {
-            body: JSON.stringify({ summary }),
+            body: JSON.stringify({ selectedTrackingSheet, summary }),
             method: "POST",
         },
     )
@@ -48,14 +49,13 @@
     getState,
 ) => {
     let hasError = false
+    const selectedTrackingSheet = ""
     fetch(
-        `/${
-            getState().meta.name
-        }/api/v1/remove_from_assessment_registry/?token=${
+        `/${getState().meta.name}/api/v1/remove_from_tracking_sheet/?token=${
             getState().token.value
         }`,
         {
-            body: JSON.stringify({ basinName, token }),
+            body: JSON.stringify({ selectedTrackingSheet, basinName, token }),
             method: "POST",
         },
     )

static/er2_303d_assess/js/actions/assessment_tracking.js

@@ -10,11 +10,19 @@
 })
 
 export const onUpdateAssessmentTracking = () => (dispatch, getState) => {
+    // This has two uses:
+    // 1) load a selected tracking sheet, i.e. when you get to the website for the first time or change which tracking sheet you are on
+    // 2) reload the data for a selected tracking sheet after it has been modified (add/update/delete of an assessment entry)
     let hasError = false
+    const selectedTrackingSheet = ""
     fetch(
-        `/${getState().meta.name}/api/v1/get_tracking/?token=${
+        `/${getState().meta.name}/api/v1/get_selected_assessment_registry/?token=${
             getState().token.value
         }`,
+        {
+            body: JSON.stringify({ selectedTrackingSheet }),
+            method: "POST",
+        },
     )
         .then((res) => {
             hasError = res.status !== 200

urls.py

@@ -23,8 +23,8 @@
     django.conf.urls.url(r"api/v1/download_assessment/$", views.download_assessment),
     django.conf.urls.url(r"api/v1/download_rationale/$", views.download_rationale_only),
     django.conf.urls.url(r"api/v1/run_rcontrol/$", views.run_rcontrol),
-    django.conf.urls.url(r"api/v1/get_tracking/$", views.get_tracking),
-    django.conf.urls.url(r"api/v1/add_to_assessment_registry/$", views.add_to_assessment_registry),
-    django.conf.urls.url(r"api/v1/remove_from_assessment_registry/$",views.remove_from_assessment_registry,),
+    django.conf.urls.url(r"api/v1/get_selected_tracking_sheet/$", views.get_selected_tracking_sheet),
+    django.conf.urls.url(r"api/v1/add_to_tracking_sheet/$", views.add_to_tracking_sheet),
+    django.conf.urls.url(r"api/v1/remove_from_tracking_sheet/$",views.remove_from_tracking_sheet,),
     django.conf.urls.url(r"api/v1/state/$", views.state),
 ]

views.py

@@ -316,24 +316,28 @@
 
 @csrf_exempt
 @return_with_exception
-def add_to_assessment_registry(request):
+def get_selected_tracking_sheet(request):
     request_state = er2_api.load_json(request.body)
-    summary = request_state["summary"]
-    ret = svcs.Tracking(request=request).add_summary_to_registry(summary)
-    return er2_api.respond({"ret": ret})
+    selectedTrackingSheet = request_state["selectedTrackingSheet"]
+    return svcs.Tracking(request=request).get_selected_registry(selectedTrackingSheet)
 
 
 @csrf_exempt
 @return_with_exception
-def remove_from_assessment_registry(request):
+def add_to_tracking_sheet(request):
     request_state = er2_api.load_json(request.body)
-    basinName = request_state["basinName"]
-    token = request_state["token"]
-    ret = svcs.Tracking(request=request).remove_summary_from_registry(basinName, token)
+    selectedTrackingSheet = request_state["selectedTrackingSheet"]
+    summary = request_state["summary"]
+    ret = svcs.Tracking(request=request).add_summary_to_tracking_sheet(selectedTrackingSheet, summary)
     return er2_api.respond({"ret": ret})
 
 
 @csrf_exempt
 @return_with_exception
-def get_tracking(request):
-    return svcs.Tracking(request=request).process()
+def remove_from_tracking_sheet(request):
+    request_state = er2_api.load_json(request.body)
+    selectedTrackingSheet = request_state["selectedTrackingSheet"]
+    basinName = request_state["basinName"]
+    token = request_state["token"]
+    ret = svcs.Tracking(request=request).remove_summary_from_tracking_sheet(selectedTrackingSheet, basinName, token)
+    return er2_api.respond({"ret": ret})