Commit c4be2ce9009d37cb36defbd642f1100dd050bbd2

Authored by kristinlaahneolsen
1 parent 31baa14f

Begynt med å implementere at det faktisk er mulig å redigere hendelser. Har prob…

…lemer med å få hentet ut en sak vha getIncident-endpointet, så har foreløpig brukt putExtra for å vise informasjonen som skal endres. Fungerer ikke optimalt enda, og har ikke fått det til å fungere slik at det blir endret i databasen
Risiko/app/src/main/AndroidManifest.xml
... ... @@ -24,7 +24,8 @@
24 24 <activity android:name="activity.NewIncident" />
25 25 <activity android:name="activity.NewEvaluation" />
26 26 <activity android:name="activity.Evaluations" />
27   - <activity android:name="activity.SequenceOfActivities"></activity>
  27 + <activity android:name="activity.SequenceOfActivities" />
  28 + <activity android:name="activity.EditIncident"></activity>
28 29 </application>
29 30  
30 31 </manifest>
31 32 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/EditIncident.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.widget.Button;
  7 +import android.widget.EditText;
  8 +import android.widget.Spinner;
  9 +
  10 +import com.risiko.risiko.R;
  11 +
  12 +import java.util.UUID;
  13 +
  14 +import api.Api;
  15 +import dataclasses.*;
  16 +import dataclasses.Incident;
  17 +import retrofit2.Call;
  18 +import retrofit2.Callback;
  19 +import retrofit2.Response;
  20 +
  21 +public class EditIncident extends AppCompatActivity {
  22 + private EditText etDate;
  23 + private EditText etLocation;
  24 + private EditText etTitle;
  25 + private EditText etDescription;
  26 + private Button editIncident;
  27 + private Spinner spinnerAssociatedRisk;
  28 +
  29 + @Override
  30 + protected void onCreate(Bundle savedInstanceState) {
  31 + super.onCreate(savedInstanceState);
  32 + setContentView(R.layout.activity_edit_incident);
  33 + Intent intent = getIntent();
  34 + Bundle b = intent.getExtras();
  35 + String id = b.getString("chosenEventId");
  36 + String title = b.getString("title");
  37 + String date = b.getString("date");
  38 + String location = b.getString("location");
  39 + String description = b.getString("description");
  40 +
  41 + etDate = findViewById(R.id.et_edit_incident_date);
  42 + etLocation = findViewById(R.id.et_edit_incident_location);
  43 + etTitle = findViewById(R.id.et_edit_incident_title);
  44 + etDescription = findViewById(R.id.et_edit_incident_description);
  45 + editIncident = findViewById(R.id.btn_edit_incident);
  46 + spinnerAssociatedRisk = findViewById(R.id.spinner_associated_risk);
  47 +
  48 +
  49 + etTitle.setText(title);
  50 + etDate.setText(date);
  51 + etLocation.setText(location);
  52 + etDescription.setText(description);
  53 +
  54 + editIncident.setOnClickListener(view -> {
  55 + if (inputAccepted()) {
  56 + String newtitle = etTitle.getText().toString();
  57 + String newdate = etDate.getText().toString();
  58 + String newlocation = etLocation.getText().toString();
  59 + String newdescription = etDescription.getText().toString();
  60 +
  61 + //TODO: MANGLER ASSOSIATEDEVAL-SPINNERTING
  62 + Api.get().editIncident(newdate, newtitle, id, "hei", newdescription, newlocation).enqueue(new Callback<dataclasses.Incident>() {
  63 + @Override
  64 + public void onResponse(Call<Incident> call, Response<Incident> response) {
  65 + System.out.println(response);
  66 + }
  67 +
  68 + @Override
  69 + public void onFailure(Call<Incident> call, Throwable t) {
  70 + t.printStackTrace();
  71 + }
  72 + });
  73 + }
  74 + });
  75 +
  76 +
  77 +
  78 + }
  79 + private boolean inputAccepted() {
  80 + if (etDate.getText().toString().isEmpty()) return false;
  81 + if (etTitle.getText().toString().isEmpty()) return false;
  82 + if (etLocation.getText().toString().isEmpty()) return false;
  83 + if (etDescription.getText().toString().isEmpty()) return false;
  84 +
  85 + return true;
  86 + }
  87 +
  88 +}
  89 +
  90 +
... ...
Risiko/app/src/main/java/activity/Incident.java
1 1 package activity;
2 2  
3 3 import android.content.DialogInterface;
  4 +import android.content.Intent;
4 5 import android.support.v7.app.AlertDialog;
5 6 import android.support.v7.app.AppCompatActivity;
6 7 import android.os.Bundle;
... ... @@ -8,6 +9,7 @@ import android.util.Log;
8 9 import android.view.LayoutInflater;
9 10 import android.view.View;
10 11 import android.widget.Button;
  12 +import android.widget.EditText;
11 13 import android.widget.ListView;
12 14 import android.widget.TextView;
13 15  
... ... @@ -84,11 +86,14 @@ public class Incident extends AppCompatActivity {
84 86 TextView tvDescription = promptView.findViewById(R.id.pop_description);
85 87 TextView tvAssociatedRisk = promptView.findViewById(R.id.pop_associated_risk);
86 88 Button deleteEvent = promptView.findViewById(R.id.pop_delete_event);
  89 + Button editEvent = promptView.findViewById(R.id.pop_edit_event);
  90 + System.out.println("SE HIT" + chosenItem.getDescription() + chosenItem.getId());
87 91  
88 92 //TODO: IMPLEMENTERE DET SLIK AT VI FÅR HENTET UT HVILKEN BRUKER SOM HAR SKREVET SAKEN
89 93 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
90 94  
91 95 deleteEvent.setOnClickListener(view -> deleteEventDialog());
  96 + editEvent.setOnClickListener(view -> editIncident(chosenItem.getId(), chosenItem.getTitle(), chosenItem.getDate(), chosenItem.getDescription(), chosenItem.getLocation()) );
92 97  
93 98  
94 99 tvDate.setText(chosenItem.getDate());
... ... @@ -105,6 +110,17 @@ public class Incident extends AppCompatActivity {
105 110  
106 111 }
107 112  
  113 + private void editIncident(String id, String title, String description, String location, String date) {
  114 + Intent intent = new Intent(this, EditIncident.class);
  115 + intent.putExtra("chosenEventId", id);
  116 + intent.putExtra("title", title);
  117 + intent.putExtra("location", location);
  118 + intent.putExtra("description", description);
  119 + intent.putExtra("date", date);
  120 + startActivity(intent);
  121 +
  122 + }
  123 +
108 124  
109 125 private void deleteEventDialog() {
110 126 new AlertDialog.Builder(this)
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -14,6 +14,7 @@ import retrofit2.http.DELETE;
14 14 import retrofit2.http.Field;
15 15 import retrofit2.http.FormUrlEncoded;
16 16 import retrofit2.http.GET;
  17 +import retrofit2.http.PATCH;
17 18 import retrofit2.http.POST;
18 19 import retrofit2.http.Path;
19 20  
... ... @@ -58,7 +59,6 @@ public interface Endpoints {
58 59 Call<String> newEvaluation(@Field("title") String title, @Field("id") String id, @Field("associatedActivity") String associatedactivity,
59 60 @Field("consequence") int consequence, @Field("measures") String measures, @Field("outcome") String outcome, @Field("probability") int probability);
60 61  
61   -
62 62 @DELETE("incident/{id}")
63 63 Call<String> deleteIncident(@Path("id") String id);
64 64  
... ... @@ -67,4 +67,10 @@ public interface Endpoints {
67 67 Call<String> deleteEvaluation(@Path("id") String id);
68 68  
69 69  
  70 + @FormUrlEncoded
  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);
  74 +
  75 +
70 76 }
... ...
Risiko/app/src/main/res/layout/activity_edit_incident.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.EditIncident">
  8 +
  9 + <LinearLayout
  10 + android:layout_width="match_parent"
  11 + android:layout_height="match_parent"
  12 + android:orientation="vertical"
  13 + android:background="@color/colorWhite"
  14 + android:padding="10dp"
  15 + android:layout_margin="15dp">
  16 +
  17 +
  18 + <TextView
  19 + android:layout_width="match_parent"
  20 + android:layout_height="wrap_content"
  21 + android:text="Endre hendelse"
  22 + android:textSize="25dp"
  23 + android:textStyle="bold"
  24 + app:layout_constraintTop_toTopOf="parent"/>
  25 +
  26 + <EditText
  27 + android:id="@+id/et_edit_incident_date"
  28 + android:layout_width="match_parent"
  29 + android:layout_height="wrap_content"
  30 + android:hint="Dato (2015-07-08):"
  31 + android:inputType="date" />
  32 +
  33 + <EditText
  34 + android:id="@+id/et_edit_incident_location"
  35 + android:layout_width="match_parent"
  36 + android:layout_height="wrap_content"
  37 + android:hint="Sted:"
  38 + android:inputType="text" />
  39 +
  40 + <EditText
  41 + android:id="@+id/et_edit_incident_title"
  42 + android:layout_width="match_parent"
  43 + android:layout_height="wrap_content"
  44 + android:hint="Tittel:"
  45 + android:inputType="text" />
  46 +
  47 + <EditText
  48 + android:id="@+id/et_edit_incident_description"
  49 + android:layout_width="match_parent"
  50 + android:layout_height="wrap_content"
  51 + android:hint="Beskrivelse:"
  52 + android:inputType="textMultiLine"
  53 + android:maxLines="5"
  54 + android:minLines="2" />
  55 +
  56 + <LinearLayout
  57 + android:padding="10dp"
  58 + android:background="@color/colorLightGray"
  59 + android:layout_marginVertical="25dp"
  60 + android:layout_width="match_parent"
  61 + android:layout_height="wrap_content"
  62 + android:orientation="horizontal">
  63 +
  64 + <TextView
  65 +
  66 + android:id="@+id/tv_associated_risk"
  67 + android:layout_width="wrap_content"
  68 + android:layout_height="wrap_content"
  69 + android:text="Tilknyttet risiko" />
  70 +
  71 + <Spinner
  72 + android:id="@+id/spinner_associated_risk"
  73 + android:layout_width="fill_parent"
  74 + android:layout_height="wrap_content" />
  75 +
  76 + </LinearLayout>
  77 +
  78 +
  79 + <LinearLayout
  80 + android:padding="10dp"
  81 + android:background="@color/colorLightGray"
  82 + android:layout_marginTop="5dp"
  83 + android:layout_marginBottom="25dp"
  84 + android:layout_width="match_parent"
  85 + android:layout_height="wrap_content"
  86 + android:orientation="horizontal">
  87 +
  88 + <TextView
  89 +
  90 + android:id="@+id/tv_read_access"
  91 + android:layout_width="wrap_content"
  92 + android:layout_height="wrap_content"
  93 + android:text="Kan leses av:" />
  94 +
  95 + <Spinner
  96 + android:id="@+id/spinner_read_access"
  97 + android:layout_width="fill_parent"
  98 + android:layout_height="wrap_content" />
  99 +
  100 + </LinearLayout>
  101 +
  102 +
  103 +
  104 + <Button
  105 + android:id="@+id/btn_edit_incident"
  106 + android:layout_width="wrap_content"
  107 + android:layout_height="wrap_content"
  108 + android:layout_gravity="center"
  109 + android:text="Lagre endring" />
  110 +
  111 + </LinearLayout>
  112 +
  113 +</android.support.constraint.ConstraintLayout>
... ...
restApi/.idea/workspace.xml
... ... @@ -2,6 +2,10 @@
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/EditIncident.java" />
  6 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_edit_incident.xml" />
  7 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
  8 + <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/Incident.java" />
5 9 <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/api/Endpoints.java" />
6 10 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
7 11 </list>
... ... @@ -51,8 +55,8 @@
51 55 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
52 56 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
53 57 <provider selected="true" editor-type-id="text-editor">
54   - <state relative-caret-position="891">
55   - <caret line="354" column="7" lean-forward="true" selection-start-line="354" selection-start-column="7" selection-end-line="354" selection-end-column="7" />
  58 + <state relative-caret-position="321">
  59 + <caret line="80" column="45" lean-forward="false" selection-start-line="80" selection-start-column="45" selection-end-line="80" selection-end-column="45" />
56 60 <folding />
57 61 </state>
58 62 </provider>
... ... @@ -102,7 +106,7 @@
102 106 <path value="$PROJECT_DIR$/package.json" />
103 107 </packageJsonPaths>
104 108 </component>
105   - <component name="ProjectFrameBounds" extendedState="1">
  109 + <component name="ProjectFrameBounds">
106 110 <option name="y" value="23" />
107 111 <option name="width" value="1440" />
108 112 <option name="height" value="873" />
... ... @@ -221,22 +225,21 @@
221 225 <workItem from="1541155443683" duration="1473000" />
222 226 <workItem from="1541596156631" duration="9351000" />
223 227 <workItem from="1541681303243" duration="9060000" />
224   - <workItem from="1542189792461" duration="3677000" />
  228 + <workItem from="1542189792461" duration="4683000" />
225 229 </task>
226 230 <servers />
227 231 </component>
228 232 <component name="TimeTrackingManager">
229   - <option name="totallyTimeSpent" value="25459000" />
  233 + <option name="totallyTimeSpent" value="26465000" />
230 234 </component>
231 235 <component name="ToolWindowManager">
232   - <frame x="0" y="23" width="1440" height="873" extended-state="1" />
233   - <editor active="true" />
  236 + <frame x="0" y="23" width="1440" height="873" extended-state="0" />
234 237 <layout>
235 238 <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" />
236 239 <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" />
237 240 <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" />
238 241 <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="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" />
  242 + <window_info id="Run" active="true" 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" />
240 243 <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" />
241 244 <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" />
242 245 <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" />
... ... @@ -289,8 +292,8 @@
289 292 </entry>
290 293 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
291 294 <provider selected="true" editor-type-id="text-editor">
292   - <state relative-caret-position="891">
293   - <caret line="354" column="7" lean-forward="true" selection-start-line="354" selection-start-column="7" selection-end-line="354" selection-end-column="7" />
  295 + <state relative-caret-position="321">
  296 + <caret line="80" column="45" lean-forward="false" selection-start-line="80" selection-start-column="45" selection-end-line="80" selection-end-column="45" />
294 297 <folding />
295 298 </state>
296 299 </provider>
... ...