Commit 3dca828120749e36be30155d7a99e8e0a9bd4174

Authored by kristinlaahneolsen
1 parent 315cfe82

Nå fungerer redigering av hendelser. Det eneste som må dobbelsjekkes er at hvis …

…bruker endrer den assosierte vurderingen, vil denne også bli endret i databasen
Risiko/app/src/main/java/activity/EditIncident.java
... ... @@ -3,12 +3,17 @@ package activity;
3 3 import android.content.Intent;
4 4 import android.support.v7.app.AppCompatActivity;
5 5 import android.os.Bundle;
  6 +import android.util.Log;
  7 +import android.widget.ArrayAdapter;
6 8 import android.widget.Button;
7 9 import android.widget.EditText;
8 10 import android.widget.Spinner;
  11 +import android.widget.Toast;
9 12  
10 13 import com.risiko.risiko.R;
11 14  
  15 +import java.util.HashMap;
  16 +import java.util.List;
12 17 import java.util.UUID;
13 18  
14 19 import api.Api;
... ... @@ -37,6 +42,10 @@ public class EditIncident extends AppCompatActivity {
37 42 String date = b.getString("date");
38 43 String location = b.getString("location");
39 44 String description = b.getString("description");
  45 + String assosiatedEval = b.getString("assosiatedEval");
  46 +
  47 +
  48 + System.out.println("SE HIT" + id + "\n" + title + "\n" + date + "\n" + location + "\n" + description );
40 49  
41 50 etDate = findViewById(R.id.et_edit_incident_date);
42 51 etLocation = findViewById(R.id.et_edit_incident_location);
... ... @@ -45,37 +54,86 @@ public class EditIncident extends AppCompatActivity {
45 54 editIncident = findViewById(R.id.btn_edit_incident);
46 55 spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
47 56  
48   -
49   - etTitle.setText(title);
50 57 etDate.setText(date);
51 58 etLocation.setText(location);
  59 + etTitle.setText(title);
52 60 etDescription.setText(description);
53 61  
  62 +
  63 +
  64 +
  65 + spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
  66 +// dbs.getAllEvaluation(evaluations);
  67 +
  68 + Api.get().getAllEvaluations()
  69 + .enqueue(new Callback<List<Evaluation>>() {
  70 +
  71 + @Override
  72 + public void onResponse(Call<List<dataclasses.Evaluation>> call, Response<List<dataclasses.Evaluation>> response) {
  73 + if (response.isSuccessful()) {
  74 + List<dataclasses.Evaluation> evaluations = response.body();
  75 + if (evaluations != null) {
  76 + HashMap<String, String> evalMap = convertToDictionaryWithIdAndTitle(evaluations);
  77 + ArrayAdapter<Object> adapter = new ArrayAdapter<>(EditIncident.this, android.R.layout.simple_spinner_item, evalMap.keySet().toArray());
  78 + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  79 + spinnerAssociatedRisk.setAdapter(adapter);
  80 +
  81 + }
  82 + }
  83 + }
  84 +
  85 + @Override
  86 + public void onFailure(Call<List<dataclasses.Evaluation>> call, Throwable t) {
  87 + //Something went completely south (maybe you lost internet connection)
  88 + Toast.makeText(EditIncident.this, "Something went wrong",
  89 + Toast.LENGTH_LONG).show();
  90 + Log.d("Error", t.getMessage());
  91 + }
  92 + });
  93 +
54 94 editIncident.setOnClickListener(view -> {
55 95 if (inputAccepted()) {
  96 +
56 97 String newtitle = etTitle.getText().toString();
57 98 String newdate = etDate.getText().toString();
58 99 String newlocation = etLocation.getText().toString();
59 100 String newdescription = etDescription.getText().toString();
60 101  
61 102 //TODO: MANGLER ASSOSIATEDEVAL-SPINNERTING
62   - Api.get().editIncident(newdate, newtitle, id, "hei", newdescription, newlocation).enqueue(new Callback<dataclasses.Incident>() {
  103 + Api.get().editIncident(id, newdate, newlocation, newtitle, newdescription, assosiatedEval).enqueue(new Callback<dataclasses.Incident>() {
63 104 @Override
64 105 public void onResponse(Call<Incident> call, Response<Incident> response) {
65 106 System.out.println(response);
  107 + System.out.println("ALT I ORDEN");
  108 +
  109 +
66 110 }
67 111  
  112 +
68 113 @Override
69 114 public void onFailure(Call<Incident> call, Throwable t) {
70 115 t.printStackTrace();
  116 + System.out.println("NOE FEILET");
71 117 }
  118 +
  119 +
72 120 });
73 121 }
  122 +
  123 + finish();
  124 + goBackToIncidents();
  125 +
74 126 });
75 127  
76 128  
77 129  
78 130 }
  131 +
  132 + private void goBackToIncidents() {
  133 + Intent intent = new Intent(this, activity.Incident.class);
  134 + startActivity(intent);
  135 + }
  136 +
79 137 private boolean inputAccepted() {
80 138 if (etDate.getText().toString().isEmpty()) return false;
81 139 if (etTitle.getText().toString().isEmpty()) return false;
... ... @@ -85,6 +143,14 @@ public class EditIncident extends AppCompatActivity {
85 143 return true;
86 144 }
87 145  
  146 + private HashMap<String, String> convertToDictionaryWithIdAndTitle(List<Evaluation> evaluations) {
  147 + HashMap<String, String> evalMap = new HashMap<>();
  148 + for (Evaluation e : evaluations) {
  149 + evalMap.put(e.getTitle(), e.getId());
  150 + }
  151 + return evalMap;
  152 + }
  153 +
88 154 }
89 155  
90 156  
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -95,8 +95,7 @@ public class Incident extends AppCompatActivity {
95 95 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
96 96  
97 97 deleteEvent.setOnClickListener(view -> deleteEventDialog());
98   - editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation()) );
99   -
  98 + editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation(), chosenItem.getAssociatedeval()));
100 99 tvTitle.setText(chosenItem.getTitle());
101 100 tvDate.setText(chosenItem.getDate());
102 101 tvLocation.setText(chosenItem.getLocation());
... ... @@ -112,13 +111,14 @@ public class Incident extends AppCompatActivity {
112 111  
113 112 }
114 113  
115   - private void editIncident(String id, String title, String description, String location, String date) {
  114 + private void editIncident(String id, String title, String date, String description, String location, String assosiatedEval) {
116 115 Intent intent = new Intent(this, EditIncident.class);
117 116 intent.putExtra("chosenEventId", id);
118 117 intent.putExtra("title", title);
119 118 intent.putExtra("location", location);
120 119 intent.putExtra("description", description);
121 120 intent.putExtra("date", date);
  121 + intent.putExtra("assosiatedEval", assosiatedEval);
122 122 startActivity(intent);
123 123  
124 124 }
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -28,7 +28,7 @@ public interface Endpoints {
28 28 //String BASEURL = "http://172.20.10.4:3000/";
29 29  
30 30 //HOS KRISTIN
31   - String BASEURL = "http://192.168.84.60:3000/";
  31 + String BASEURL = "http://192.168.84.67:3000/";
32 32  
33 33 //ØYVIN FIX
34 34 //String BASEURL ="http://risikoapi.harm.no/";
... ... @@ -69,8 +69,8 @@ public interface Endpoints {
69 69  
70 70 @FormUrlEncoded
71 71 @PATCH("incident/{id}")
72   - Call<Incident> editIncident(@Field("date") String date, @Field("title") String title, @Field("id") String id, @Field("associatedEval") String associatedEval,
73   - @Field("description") String description, @Field("location") String locatione);
  72 + Call<Incident> editIncident(@Path("id") String id, @Field("date") String date, @Field("location") String location,
  73 + @Field("title") String title, @Field("description") String description, @Field("associatedEval") String associatedEval);
74 74  
75 75  
76 76 }
... ...
restApi/.idea/workspace.xml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <project version="4">
3 3 <component name="ChangeListManager">
4   - <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="" />
  4 + <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
  5 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditIncident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditIncident.java" />
  6 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
  7 + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
  8 + </list>
5 9 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
6 10 <option name="TRACKING_ENABLED" value="true" />
7 11 <option name="SHOW_DIALOG" value="false" />
... ... @@ -48,8 +52,8 @@
48 52 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
49 53 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
50 54 <provider selected="true" editor-type-id="text-editor">
51   - <state relative-caret-position="216">
52   - <caret line="76" column="125" lean-forward="true" selection-start-line="76" selection-start-column="125" selection-end-line="76" selection-end-column="125" />
  55 + <state relative-caret-position="592">
  56 + <caret line="126" column="46" lean-forward="false" selection-start-line="126" selection-start-column="46" selection-end-line="126" selection-end-column="46" />
53 57 <folding />
54 58 </state>
55 59 </provider>
... ... @@ -99,7 +103,7 @@
99 103 <path value="$PROJECT_DIR$/package.json" />
100 104 </packageJsonPaths>
101 105 </component>
102   - <component name="ProjectFrameBounds">
  106 + <component name="ProjectFrameBounds" extendedState="1">
103 107 <option name="y" value="23" />
104 108 <option name="width" value="1440" />
105 109 <option name="height" value="873" />
... ... @@ -218,21 +222,21 @@
218 222 <workItem from="1541155443683" duration="1473000" />
219 223 <workItem from="1541596156631" duration="9351000" />
220 224 <workItem from="1541681303243" duration="9060000" />
221   - <workItem from="1542189792461" duration="4744000" />
  225 + <workItem from="1542189792461" duration="6867000" />
222 226 </task>
223 227 <servers />
224 228 </component>
225 229 <component name="TimeTrackingManager">
226   - <option name="totallyTimeSpent" value="26526000" />
  230 + <option name="totallyTimeSpent" value="28649000" />
227 231 </component>
228 232 <component name="ToolWindowManager">
229   - <frame x="0" y="23" width="1440" height="873" extended-state="0" />
230   - <editor active="true" />
  233 + <frame x="0" y="23" width="1440" height="873" extended-state="1" />
231 234 <layout>
232   - <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.71128106" order="0" side_tool="false" content_ui="combo" />
  235 + <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.71128106" order="0" side_tool="false" content_ui="combo" />
233 236 <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
234 237 <window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
235 238 <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="true" content_ui="tabs" />
  239 + <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
236 240 <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.3277635" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
237 241 <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
238 242 <window_info id="npm" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.20014094" sideWeight="0.28871894" order="2" side_tool="true" content_ui="tabs" />
... ... @@ -246,7 +250,6 @@
246 250 <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
247 251 <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
248 252 <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
249   - <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
250 253 <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
251 254 </layout>
252 255 </component>
... ... @@ -286,8 +289,8 @@
286 289 </entry>
287 290 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
288 291 <provider selected="true" editor-type-id="text-editor">
289   - <state relative-caret-position="216">
290   - <caret line="76" column="125" lean-forward="true" selection-start-line="76" selection-start-column="125" selection-end-line="76" selection-end-column="125" />
  292 + <state relative-caret-position="592">
  293 + <caret line="126" column="46" lean-forward="false" selection-start-line="126" selection-start-column="46" selection-end-line="126" selection-end-column="46" />
291 294 <folding />
292 295 </state>
293 296 </provider>
... ...