Commit c154f4898c1e490bc5bb5c1386c60037aa6b199e

Authored by kristinlaahneolsen
1 parent 4db99cdc

Har laget klar en hendelseslogg-aktivitet, slik at vi kan sørge for appens integ…

…ritet gjennom loggføring. I forbindelse med dette har jeg også oppdatert APIet, slik at vi kan redigere på vurderinger som er lagt inn, av den grunn at det er mer naturlig å føre en logg med navn på hvem som har redigert disse. En uønsket hendelse derimot bør jo ikke kunne endres av andre enn den personen som har skrevet saken
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -25,7 +25,8 @@
25 25 <activity android:name="activity.NewEvaluation" />
26 26 <activity android:name="activity.Evaluations" />
27 27 <activity android:name="activity.SequenceOfActivities" />
28   - <activity android:name="activity.EditIncident"></activity>
  28 + <activity android:name="activity.EditIncident" />
  29 + <activity android:name="activity.Log"></activity>
29 30 </application>
30 31  
31 32 </manifest>
32 33 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/Incident.java
... ... @@ -99,6 +99,7 @@ public class Incident extends AppCompatActivity {
99 99 TextView tvAssociatedRisk = promptView.findViewById(R.id.pop_associated_risk);
100 100 Button deleteEvent = promptView.findViewById(R.id.pop_delete_event);
101 101 Button editEvent = promptView.findViewById(R.id.pop_edit_event);
  102 + Button seeLog = promptView.findViewById(R.id.btn_see_log);
102 103  
103 104 //TODO TEST PÅ HASH
104 105 MessageDigest md = null;
... ... @@ -120,7 +121,7 @@ public class Incident extends AppCompatActivity {
120 121  
121 122 deleteEvent.setOnClickListener(view -> deleteEventDialog());
122 123 editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation(), chosenItem.getAssociatedeval()));
123   -
  124 + seeLog.setOnClickListener(view -> startActivity(new Intent(this, activity.Log.class)));
124 125  
125 126 System.out.println("EVALID" + chosenItem.getAssociatedeval());
126 127 Api.get().getEvaluation(chosenItem.getAssociatedeval()).enqueue(new Callback<Evaluation>() {
... ...
Risiko/app/src/main/java/activity/Log.java 0 → 100644
  1 +package activity;
  2 +
  3 +import android.content.Intent;
  4 +import android.support.v7.app.AppCompatActivity;
  5 +import android.os.Bundle;
  6 +import android.support.v7.widget.Toolbar;
  7 +import android.view.Menu;
  8 +import android.view.MenuItem;
  9 +import android.widget.Toast;
  10 +
  11 +import com.risiko.risiko.R;
  12 +
  13 +public class Log extends AppCompatActivity {
  14 +
  15 + @Override
  16 + protected void onCreate(Bundle savedInstanceState) {
  17 + super.onCreate(savedInstanceState);
  18 + setContentView(R.layout.activity_log);
  19 + Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  20 + setSupportActionBar(myToolbar);
  21 +
  22 +
  23 + }
  24 +
  25 + @Override
  26 + public boolean onCreateOptionsMenu (Menu menu) {
  27 + getMenuInflater().inflate(R.menu.main, menu);
  28 + return true;
  29 + }
  30 +
  31 +
  32 + @Override
  33 + public boolean onOptionsItemSelected(MenuItem item) {
  34 + switch (item.getItemId()) {
  35 + case R.id.action_logout:
  36 + //TODO: LEGG TIL LOGG-UT-FUNKSJON
  37 + Toast.makeText(Log.this, "Logger ut",
  38 + Toast.LENGTH_LONG).show();
  39 + return true;
  40 +
  41 + case R.id.action_home:
  42 + Intent intent = new Intent(this, MainMenu.class);
  43 + startActivity(intent);
  44 + return true;
  45 +
  46 + default:
  47 + return super.onOptionsItemSelected(item);
  48 +
  49 + }
  50 + }
  51 +
  52 +}
... ...
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.67:3000/";
  31 + String BASEURL = "http://192.168.84.71:3000/";
32 32  
33 33 //ØYVIN FIX
34 34 //String BASEURL ="http://risikoapi.harm.no/";
... ...
Risiko/app/src/main/res/drawable/ic_eye.xml 0 → 100644
  1 +<vector xmlns:android="http://schemas.android.com/apk/res/android"
  2 + android:width="24dp"
  3 + android:height="24dp"
  4 + android:viewportWidth="24.0"
  5 + android:viewportHeight="24.0">
  6 + <path
  7 + android:fillColor="#f1754d"
  8 + android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
  9 +</vector>
... ...
Risiko/app/src/main/res/layout/activity_log.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent"
  7 + tools:context="com.risiko.risiko.activity.Log">
  8 +
  9 + <include layout="@layout/toolbar"/>
  10 +
  11 + <TextView
  12 + android:layout_width="wrap_content"
  13 + android:layout_height="wrap_content"
  14 + android:text="HELLO"
  15 + android:layout_marginTop="200dp"/>
  16 +
  17 +</android.support.constraint.ConstraintLayout>
... ...
Risiko/app/src/main/res/layout/popup_event.xml
... ... @@ -58,8 +58,6 @@
58 58 android:background="@color/colorPrimaryDark"/>
59 59  
60 60  
61   -
62   -
63 61 <LinearLayout
64 62 android:layout_width="match_parent"
65 63 android:layout_height="wrap_content"
... ... @@ -139,9 +137,20 @@
139 137 android:layout_height="wrap_content"
140 138 android:text="..."/>
141 139  
142   - </LinearLayout>
143 140  
144 141  
  142 + </LinearLayout>
  143 +
  144 + <Button
  145 + android:id="@+id/btn_see_log"
  146 + android:drawableLeft="@drawable/ic_eye"
  147 + android:layout_marginTop="50dp"
  148 + android:layout_gravity="center"
  149 + android:padding="10dp"
  150 + android:background="@color/colorLightGray"
  151 + android:layout_width="200dp"
  152 + android:layout_height="wrap_content"
  153 + android:text="@string/see_log"/>
145 154  
146 155  
147 156 </LinearLayout>
148 157 \ No newline at end of file
... ...
Risiko/app/src/main/res/values/strings.xml
... ... @@ -39,6 +39,7 @@
39 39 <string name="no">Nei</string>
40 40 <string name="areYouSureEvent">Er du sikker på at du vil slette denne hendelsen?</string>
41 41 <string name="added_by">Lagt til av:</string>
  42 + <string name="see_log">Se hendelseslogg</string>
42 43  
43 44  
44 45 </resources>
... ...
restApi/.idea/workspace.xml
... ... @@ -2,7 +2,15 @@
2 2 <project version="4">
3 3 <component name="ChangeListManager">
4 4 <list default="true" id="0e20d303-9de8-4113-bfd9-019e72b304dc" name="Default" comment="">
  5 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Log.java" />
  6 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/drawable/ic_eye.xml" />
  7 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_log.xml" />
  8 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
5 9 <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" />
  10 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
  11 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/popup_event.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/popup_event.xml" />
  12 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/res/values/strings.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/values/strings.xml" />
  13 + <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
6 14 <change beforePath="$PROJECT_DIR$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
7 15 </list>
8 16 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
... ... @@ -51,8 +59,28 @@
51 59 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
52 60 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
53 61 <provider selected="true" editor-type-id="text-editor">
54   - <state relative-caret-position="424">
55   - <caret line="263" column="4" lean-forward="true" selection-start-line="263" selection-start-column="4" selection-end-line="263" selection-end-column="4" />
  62 + <state relative-caret-position="329">
  63 + <caret line="286" column="30" lean-forward="true" selection-start-line="286" selection-start-column="30" selection-end-line="286" selection-end-column="30" />
  64 + <folding />
  65 + </state>
  66 + </provider>
  67 + </entry>
  68 + </file>
  69 + <file leaf-file-name="server.js" pinned="false" current-in-tab="false">
  70 + <entry file="file://$PROJECT_DIR$/server.js">
  71 + <provider selected="true" editor-type-id="text-editor">
  72 + <state relative-caret-position="225">
  73 + <caret line="15" column="17" lean-forward="false" selection-start-line="15" selection-start-column="17" selection-end-line="15" selection-end-column="17" />
  74 + <folding />
  75 + </state>
  76 + </provider>
  77 + </entry>
  78 + </file>
  79 + <file leaf-file-name="application.js" pinned="false" current-in-tab="false">
  80 + <entry file="file://$PROJECT_DIR$/node_modules/express/lib/application.js">
  81 + <provider selected="true" editor-type-id="text-editor">
  82 + <state relative-caret-position="9165">
  83 + <caret line="617" column="23" lean-forward="false" selection-start-line="617" selection-start-column="23" selection-end-line="617" selection-end-column="23" />
56 84 <folding />
57 85 </state>
58 86 </provider>
... ... @@ -102,7 +130,7 @@
102 130 <path value="$PROJECT_DIR$/package.json" />
103 131 </packageJsonPaths>
104 132 </component>
105   - <component name="ProjectFrameBounds" fullScreen="true">
  133 + <component name="ProjectFrameBounds" extendedState="6" fullScreen="true">
106 134 <option name="y" value="23" />
107 135 <option name="width" value="1440" />
108 136 <option name="height" value="873" />
... ... @@ -123,6 +151,7 @@
123 151 </navigator>
124 152 <panes>
125 153 <pane id="Scope" />
  154 + <pane id="Scratches" />
126 155 <pane id="ProjectPane">
127 156 <subPane>
128 157 <expand>
... ... @@ -151,7 +180,6 @@
151 180 <select />
152 181 </subPane>
153 182 </pane>
154   - <pane id="Scratches" />
155 183 </panes>
156 184 </component>
157 185 <component name="PropertiesComponent">
... ... @@ -222,24 +250,25 @@
222 250 <workItem from="1541596156631" duration="9351000" />
223 251 <workItem from="1541681303243" duration="9060000" />
224 252 <workItem from="1542189792461" duration="7537000" />
225   - <workItem from="1542881688157" duration="125000" />
  253 + <workItem from="1542881688157" duration="372000" />
  254 + <workItem from="1543226716067" duration="914000" />
226 255 </task>
227 256 <servers />
228 257 </component>
229 258 <component name="TimeTrackingManager">
230   - <option name="totallyTimeSpent" value="29444000" />
  259 + <option name="totallyTimeSpent" value="30605000" />
231 260 </component>
232 261 <component name="ToolWindowManager">
233 262 <frame x="0" y="0" width="1440" height="900" extended-state="6" />
234 263 <editor active="true" />
235 264 <layout>
236   - <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.70495766" order="0" side_tool="false" content_ui="combo" />
  265 + <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.69244605" order="0" side_tool="false" content_ui="combo" />
237 266 <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" />
238 267 <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" />
239 268 <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" />
240   - <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.3277635" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
  269 + <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32769045" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
241 270 <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" />
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.29504234" order="2" side_tool="true" content_ui="tabs" />
  271 + <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.30755395" order="2" side_tool="true" content_ui="tabs" />
243 272 <window_info id="Structure" active="false" anchor="left" 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" />
244 273 <window_info id="Terminal" 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="9" side_tool="false" content_ui="tabs" />
245 274 <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.39903265" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
... ... @@ -265,6 +294,38 @@
265 294 <watches-manager />
266 295 </component>
267 296 <component name="editorHistoryManager">
  297 + <entry file="file://$PROJECT_DIR$/node_modules/express/lib/application.js">
  298 + <provider selected="true" editor-type-id="text-editor">
  299 + <state relative-caret-position="9165">
  300 + <caret line="617" column="23" lean-forward="false" selection-start-line="617" selection-start-column="23" selection-end-line="617" selection-end-column="23" />
  301 + <folding />
  302 + </state>
  303 + </provider>
  304 + </entry>
  305 + <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
  306 + <provider selected="true" editor-type-id="text-editor">
  307 + <state relative-caret-position="2730">
  308 + <caret line="182" column="0" lean-forward="false" selection-start-line="182" selection-start-column="0" selection-end-line="183" selection-end-column="0" />
  309 + <folding />
  310 + </state>
  311 + </provider>
  312 + </entry>
  313 + <entry file="file://$PROJECT_DIR$/package.json">
  314 + <provider selected="true" editor-type-id="text-editor">
  315 + <state relative-caret-position="120">
  316 + <caret line="8" column="48" lean-forward="false" selection-start-line="8" selection-start-column="48" selection-end-line="8" selection-end-column="48" />
  317 + <folding />
  318 + </state>
  319 + </provider>
  320 + </entry>
  321 + <entry file="file://$PROJECT_DIR$/server.js">
  322 + <provider selected="true" editor-type-id="text-editor">
  323 + <state relative-caret-position="225">
  324 + <caret line="15" column="17" lean-forward="false" selection-start-line="15" selection-start-column="17" selection-end-line="15" selection-end-column="17" />
  325 + <folding />
  326 + </state>
  327 + </provider>
  328 + </entry>
268 329 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
269 330 <provider selected="true" editor-type-id="text-editor">
270 331 <state relative-caret-position="0">
... ... @@ -288,18 +349,34 @@
288 349 </state>
289 350 </provider>
290 351 </entry>
291   - <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
  352 + <entry file="file://$PROJECT_DIR$/package.json">
  353 + <provider selected="true" editor-type-id="text-editor">
  354 + <state relative-caret-position="120">
  355 + <caret line="8" column="48" lean-forward="false" selection-start-line="8" selection-start-column="48" selection-end-line="8" selection-end-column="48" />
  356 + <folding />
  357 + </state>
  358 + </provider>
  359 + </entry>
  360 + <entry file="file://$PROJECT_DIR$/node_modules/express/lib/application.js">
292 361 <provider selected="true" editor-type-id="text-editor">
293   - <state relative-caret-position="424">
294   - <caret line="263" column="4" lean-forward="true" selection-start-line="263" selection-start-column="4" selection-end-line="263" selection-end-column="4" />
  362 + <state relative-caret-position="9165">
  363 + <caret line="617" column="23" lean-forward="false" selection-start-line="617" selection-start-column="23" selection-end-line="617" selection-end-column="23" />
295 364 <folding />
296 365 </state>
297 366 </provider>
298 367 </entry>
299   - <entry file="file://$PROJECT_DIR$/package.json">
  368 + <entry file="file://$PROJECT_DIR$/server.js">
300 369 <provider selected="true" editor-type-id="text-editor">
301   - <state relative-caret-position="120">
302   - <caret line="8" column="48" lean-forward="false" selection-start-line="8" selection-start-column="48" selection-end-line="8" selection-end-column="48" />
  370 + <state relative-caret-position="225">
  371 + <caret line="15" column="17" lean-forward="false" selection-start-line="15" selection-start-column="17" selection-end-line="15" selection-end-column="17" />
  372 + <folding />
  373 + </state>
  374 + </provider>
  375 + </entry>
  376 + <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
  377 + <provider selected="true" editor-type-id="text-editor">
  378 + <state relative-caret-position="329">
  379 + <caret line="286" column="30" lean-forward="true" selection-start-line="286" selection-start-column="30" selection-end-line="286" selection-end-column="30" />
303 380 <folding />
304 381 </state>
305 382 </provider>
... ...
restApi/api/routes/routes.js
... ... @@ -261,6 +261,40 @@ var appRouter = function(app) {
261 261 }
262 262 );
263 263 });
  264 +
  265 +
  266 +
  267 + /**
  268 + * Update an evaluation (a patch request at http://localhost:3000/incident/{id} will update the evaluation with the params passed in the request body)
  269 + */
  270 + app.patch("/evaluation/:id", function (req, res) {
  271 +
  272 + if (!req.params.id) {
  273 + logEndpoint("patch /evaluation", null, "ID missing");
  274 + return res.status(400).send("Missing id");
  275 + }
  276 +
  277 + if (!req.body.title || !req.body.outcome || !req.body.measures || !req.body.consequence || !req.body.probability || !req.body.associatedActivity) {
  278 + logEndpoint("patch /evaluation", null, "Missing params in body");
  279 + return res.status(400).send("Missing params");
  280 + }
  281 +
  282 + const params = [req.body.title, req.body.outcome, req.body.measures, req.body.consequence, req.body.probability, req.body.associatedActivity, req.params.id];
  283 + db.execute("UPDATE risk.evaluation " +
  284 + "SET title=?, outcome=?, measures=?, consequence=?, probability=?, associatedActivity=? " +
  285 + "WHERE id=?",
  286 + params,
  287 + { prepare: true },
  288 + function (err) {
  289 + if (err) {
  290 + logEndpoint("patch /evaluation", err, "Bad request, see API log");
  291 + return res.status(400).send("Bad Request");
  292 + }
  293 + logEndpoint("patch /evaluation", err, "Success, evaluation updated");
  294 + return res.status(200).send("Evaluation updated");
  295 + }
  296 + );
  297 + });
264 298  
265 299  
266 300 /**
... ...