Commit 26c699a72d4c2dde531bf5423e72aa32b10f5bb7

Authored by kristinlaahneolsen
1 parent c154f489

Nå fungerer endring av evalueringer via app (uten at hendelser kræsjer)

Risiko/app/src/main/AndroidManifest.xml
... ... @@ -26,7 +26,8 @@
26 26 <activity android:name="activity.Evaluations" />
27 27 <activity android:name="activity.SequenceOfActivities" />
28 28 <activity android:name="activity.EditIncident" />
29   - <activity android:name="activity.Log"></activity>
  29 + <activity android:name="activity.Log" />
  30 + <activity android:name="activity.EditEvaluation"></activity>
30 31 </application>
31 32  
32 33 </manifest>
33 34 \ No newline at end of file
... ...
Risiko/app/src/main/java/activity/EditEvaluation.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.MenuItem;
  8 +import android.widget.ArrayAdapter;
  9 +import android.widget.Button;
  10 +import android.widget.EditText;
  11 +import android.widget.Spinner;
  12 +import android.widget.Toast;
  13 +
  14 +import com.risiko.risiko.R;
  15 +
  16 +import api.Api;
  17 +import dataclasses.*;
  18 +import retrofit2.Call;
  19 +import retrofit2.Callback;
  20 +import retrofit2.Response;
  21 +
  22 +public class EditEvaluation extends AppCompatActivity {
  23 + private EditText etTitle;
  24 + private EditText etOutcome;
  25 + private EditText etMeasures;
  26 + private Spinner spinnerConsequence, spinnerProbability;
  27 + Button editEvaluation;
  28 +
  29 +
  30 +
  31 + @Override
  32 + protected void onCreate(Bundle savedInstanceState) {
  33 + super.onCreate(savedInstanceState);
  34 + setContentView(R.layout.activity_edit_evaluation);
  35 +
  36 + Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  37 + setSupportActionBar(myToolbar);
  38 +
  39 + Intent intent = getIntent();
  40 + Bundle b = intent.getExtras();
  41 + String id = b.getString("id");
  42 + String title = b.getString("title");
  43 + String outcome = b.getString("outcome");
  44 + String measures = b.getString("measures");
  45 + int consequence = b.getInt("consequence");
  46 + int probability = b.getInt("probability");
  47 + String assosiatedActivity = b.getString("associatedActivity");
  48 + setupSpinners();
  49 +
  50 +
  51 + etTitle = findViewById(R.id.et_editEval_title);
  52 + etOutcome = findViewById(R.id.et_editEval_outcome);
  53 + etMeasures = findViewById(R.id.et_editEval_action);
  54 + spinnerConsequence = findViewById(R.id.spinner_consequence);
  55 + spinnerProbability = findViewById(R.id.spinner_probability);
  56 + editEvaluation = findViewById(R.id.btn_edit_eval);
  57 +
  58 + etTitle.setText(title);
  59 + etOutcome.setText(outcome);
  60 + etMeasures.setText(measures);
  61 +
  62 +
  63 + String stringConsequence = spinnerConsequence.getSelectedItem().toString();
  64 + String stringProbability = spinnerProbability.getSelectedItem().toString();
  65 +
  66 + int consequenceValue = getConsequenceValue(stringConsequence);
  67 + int probabilityValue = getProbabilityValue(stringProbability);
  68 +
  69 + editEvaluation.setOnClickListener(view -> {
  70 + if (inputAccepted()) {
  71 +
  72 + String newtitle = etTitle.getText().toString();
  73 + String newOutcome = etOutcome.getText().toString();
  74 + String newMeasures = etMeasures.getText().toString();
  75 +
  76 + Api.get().editEvaluation(id, newtitle, newOutcome, newMeasures, consequenceValue, probabilityValue, assosiatedActivity).enqueue(new Callback<Evaluation>() {
  77 + @Override
  78 + public void onResponse(Call<Evaluation> call, Response<Evaluation> response) {
  79 + System.out.println(response);
  80 + }
  81 +
  82 + @Override
  83 + public void onFailure(Call<Evaluation> call, Throwable t) {
  84 + t.printStackTrace();
  85 +
  86 + }
  87 + });
  88 +
  89 + }
  90 + finish();
  91 + goBackToActivities();
  92 +
  93 + });
  94 + }
  95 +
  96 +
  97 + private void goBackToActivities() {
  98 + Intent intent = new Intent(this, Activities.class);
  99 + startActivity(intent);
  100 + }
  101 +
  102 + private boolean inputAccepted() {
  103 + if (etTitle.getText().toString().isEmpty()) return false;
  104 + if (etOutcome.getText().toString().isEmpty()) return false;
  105 + if (etMeasures.getText().toString().isEmpty()) return false;
  106 +
  107 + return true;
  108 + }
  109 +
  110 + private void setupSpinners() {
  111 + spinnerConsequence = findViewById(R.id.spinner_consequence);
  112 + ArrayAdapter<CharSequence> consequenceAdapter = ArrayAdapter.createFromResource(this, R.array.consequence_array, android.R.layout.simple_spinner_item);
  113 + consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  114 + spinnerConsequence.setAdapter(consequenceAdapter);
  115 +
  116 + spinnerProbability = findViewById(R.id.spinner_probability);
  117 + ArrayAdapter<CharSequence> probabilityAdapter = ArrayAdapter.createFromResource(this, R.array.probability_array, android.R.layout.simple_spinner_item);
  118 + consequenceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  119 + spinnerProbability.setAdapter(probabilityAdapter);
  120 + }
  121 +
  122 + private int getConsequenceValue(String consequence) {
  123 + switch (consequence) {
  124 + case "Ufarlig": return 1;
  125 + case "Moderate": return 2;
  126 + case "Alvorlig": return 3;
  127 + default: return -1;
  128 + }
  129 + }
  130 +
  131 + private int getProbabilityValue(String probability) {
  132 + switch (probability) {
  133 + case "Lav": return 1;
  134 + case "Middels": return 2;
  135 + case "Stor": return 3;
  136 + default: return -1;
  137 + }
  138 + }
  139 +
  140 +
  141 + @Override
  142 + public boolean onOptionsItemSelected(MenuItem item) {
  143 + switch (item.getItemId()) {
  144 + case R.id.action_logout:
  145 + //TODO: LEGG TIL LOGG-UT-FUNKSJON
  146 + Toast.makeText(EditEvaluation.this, "Logger ut",
  147 + Toast.LENGTH_LONG).show();
  148 + return true;
  149 +
  150 + case R.id.action_home:
  151 + Intent intent = new Intent(this, MainMenu.class);
  152 + startActivity(intent);
  153 + return true;
  154 +
  155 + default:
  156 + return super.onOptionsItemSelected(item);
  157 +
  158 + }
  159 + }
  160 +}
... ...
Risiko/app/src/main/java/activity/Evaluations.java
... ... @@ -111,12 +111,12 @@ public class Evaluations extends AppCompatActivity {
111 111  
112 112 private void showEvaluationPopup(Evaluation evaluation) {
113 113  
  114 +
114 115 LayoutInflater layoutInflater = LayoutInflater.from(this);
115 116 View promptView = layoutInflater.inflate(R.layout.popup_evaluation, null);
116 117 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
117 118 alertDialogBuilder.setView(promptView);
118 119  
119   -
120 120 TextView headline = promptView.findViewById(R.id.pop_headline);
121 121 TextView outcome = promptView.findViewById(R.id.pop_possible_outcomes);
122 122 TextView measures = promptView.findViewById(R.id.pop_measures);
... ... @@ -129,9 +129,9 @@ public class Evaluations extends AppCompatActivity {
129 129 //TODO: IMPLEMENTERE DET SLIK AT VI FÅR HENTET UT HVILKEN BRUKER SOM HAR SKREVET SAKEN
130 130 TextView addedBy = promptView.findViewById(R.id.tv_added_by);
131 131  
132   - //Button deleteEvaluation = promptView.findViewById(R.id.pop_delete_evaluation);
133   - //deleteEvaluation.setOnClickListener(view -> deleteEvaluationDialog());
134   -
  132 + Button updateEvaluation = promptView.findViewById(R.id.pop_edit_evaluation);
  133 + updateEvaluation.setOnClickListener(view -> editEvaluation(evaluation.getTitle(), evaluation.getOutcome(),
  134 + evaluation.getMeasures(), evaluation.getConsequence(), evaluation.getProbability(), evaluation.getId(), evaluation.getAssociatedactivity()));
135 135  
136 136 if (evaluation.getProbability() == 3) {
137 137 probabilityHigh.setTextColor(getResources().getColor(R.color.colorDarkGreen));
... ... @@ -169,6 +169,18 @@ public class Evaluations extends AppCompatActivity {
169 169 alert.show();
170 170 }
171 171  
  172 + private void editEvaluation(String title, String outcome, String measures, int consequence, int probability, String id, String associatedactivity) {
  173 + Intent intent = new Intent(this, EditEvaluation.class);
  174 + intent.putExtra("title", title);
  175 + intent.putExtra("outcome", outcome);
  176 + intent.putExtra("measures", measures);
  177 + intent.putExtra("consequence", consequence);
  178 + intent.putExtra("probability", probability);
  179 + intent.putExtra("id", id);
  180 + intent.putExtra("associatedActivity", associatedactivity);
  181 + startActivity(intent);
  182 + }
  183 +
172 184  
173 185 //TODO: Hvis vi får tid, må vi se på denne delen. Det bør ikke være mulig å slette en vurdering som har en hendelse knyttet opp til seg
174 186 //TODO: Derfor er denne delen av koden kommentert ut
... ...
Risiko/app/src/main/java/api/Endpoints.java
... ... @@ -66,6 +66,10 @@ public interface Endpoints {
66 66 @DELETE("evaluation/{id}")
67 67 Call<String> deleteEvaluation(@Path("id") String id);
68 68  
  69 + @FormUrlEncoded
  70 + @PATCH("evaluation/{id}")
  71 + Call<Evaluation> editEvaluation(@Path("id") String id, @Field("title") String title, @Field("outcome") String outcome, @Field("measures") String measures, @Field("consequence") int consequence,
  72 + @Field("probability") int probability, @Field("associatedActivity") String associatedactivity);
69 73  
70 74 @FormUrlEncoded
71 75 @PATCH("incident/{id}")
... ...
Risiko/app/src/main/res/layout/activity_edit_evaluation.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.EditEvaluation">
  8 +
  9 + <include layout="@layout/toolbar"/>
  10 +
  11 + <LinearLayout
  12 + android:layout_width="match_parent"
  13 + android:layout_height="match_parent"
  14 + android:orientation="vertical"
  15 + android:background="@color/colorWhite"
  16 + android:padding="10dp"
  17 + android:layout_marginTop="70dp"
  18 + android:layout_marginBottom="15dp"
  19 + android:layout_marginHorizontal="15dp">
  20 +
  21 +
  22 + <TextView
  23 + android:layout_width="match_parent"
  24 + android:layout_height="wrap_content"
  25 + android:text="Endre vurdering"
  26 + android:textColor="@color/colorPrimaryDark"
  27 + android:textSize="25dp"
  28 + android:textStyle="bold"/>
  29 +
  30 +
  31 + <EditText
  32 + android:id="@+id/et_editEval_title"
  33 + android:layout_width="match_parent"
  34 + android:layout_height="wrap_content"
  35 + android:layout_marginVertical="10dp"
  36 + android:hint="Tittel:"
  37 + android:inputType="text" />
  38 +
  39 + <EditText
  40 + android:id="@+id/et_editEval_outcome"
  41 + android:layout_width="match_parent"
  42 + android:layout_height="wrap_content"
  43 + android:layout_marginVertical="10dp"
  44 + android:hint="Mulig utfall:"
  45 + android:inputType="text" />
  46 +
  47 + <EditText
  48 + android:id="@+id/et_editEval_action"
  49 + android:layout_width="match_parent"
  50 + android:layout_height="wrap_content"
  51 + android:layout_marginVertical="10dp"
  52 + android:hint="Tiltak:"
  53 + android:inputType="text" />
  54 +
  55 + <LinearLayout
  56 + android:padding="10dp"
  57 + android:background="@color/colorLightGray"
  58 + android:layout_marginVertical="25dp"
  59 + android:layout_width="match_parent"
  60 + android:layout_height="wrap_content"
  61 + android:orientation="horizontal">
  62 +
  63 + <TextView
  64 + android:layout_marginEnd="20dp"
  65 + android:id="@+id/tv_consequence"
  66 + android:layout_width="wrap_content"
  67 + android:layout_height="wrap_content"
  68 + android:text="@string/consequence"
  69 + android:textStyle="bold"
  70 + android:textSize="17sp"/>
  71 +
  72 + <Spinner
  73 + android:id="@+id/spinner_consequence"
  74 + android:layout_width="fill_parent"
  75 + android:layout_height="wrap_content" />
  76 +
  77 + </LinearLayout>
  78 +
  79 + <LinearLayout
  80 + android:padding="10dp"
  81 + android:background="@color/colorLightGray"
  82 + android:layout_width="match_parent"
  83 + android:layout_height="wrap_content"
  84 + android:orientation="horizontal">
  85 +
  86 + <TextView
  87 + android:id="@+id/tv_probability"
  88 + android:layout_width="wrap_content"
  89 + android:layout_height="wrap_content"
  90 + android:layout_marginEnd="20dp"
  91 + android:text="@string/probability"
  92 + android:textSize="17sp"
  93 + android:textStyle="bold" />
  94 +
  95 + <Spinner
  96 + android:id="@+id/spinner_probability"
  97 + android:layout_width="fill_parent"
  98 + android:layout_height="wrap_content" />
  99 +
  100 + </LinearLayout>
  101 +
  102 + <Button
  103 + android:id="@+id/btn_edit_eval"
  104 + android:layout_width="150dp"
  105 + android:layout_height="wrap_content"
  106 + android:layout_gravity="center"
  107 + android:layout_marginTop="30dp"
  108 + android:text="Lagre endring " />
  109 +
  110 + </LinearLayout>
  111 +
  112 +</android.support.constraint.ConstraintLayout>
... ...
Risiko/app/src/main/res/layout/popup_evaluation.xml
... ... @@ -31,10 +31,10 @@
31 31  
32 32 <Button
33 33 android:layout_marginRight="15dp"
34   - android:id="@+id/pop_delete_evaluation"
  34 + android:id="@+id/pop_edit_evaluation"
35 35 android:layout_width="30dp"
36 36 android:layout_height="30dp"
37   - android:background="@drawable/ic_delete"/>
  37 + android:background="@drawable/ic_edit"/>
38 38  
39 39 </LinearLayout>
40 40  
... ...
restApi/.idea/workspace.xml
... ... @@ -2,16 +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/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" />
  5 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/java/activity/EditEvaluation.java" />
  6 + <change beforePath="" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/res/layout/activity_edit_evaluation.xml" />
8 7 <change beforePath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" afterPath="$PROJECT_DIR$/../Risiko/app/src/main/AndroidManifest.xml" />
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 8 <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" />
14   - <change beforePath="$PROJECT_DIR$/api/routes/routes.js" afterPath="$PROJECT_DIR$/api/routes/routes.js" />
15 9 </list>
16 10 <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
17 11 <option name="TRACKING_ENABLED" value="true" />
... ... @@ -59,8 +53,8 @@
59 53 <file leaf-file-name="routes.js" pinned="false" current-in-tab="true">
60 54 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
61 55 <provider selected="true" editor-type-id="text-editor">
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" />
  56 + <state relative-caret-position="229">
  57 + <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
64 58 <folding />
65 59 </state>
66 60 </provider>
... ... @@ -251,12 +245,12 @@
251 245 <workItem from="1541681303243" duration="9060000" />
252 246 <workItem from="1542189792461" duration="7537000" />
253 247 <workItem from="1542881688157" duration="372000" />
254   - <workItem from="1543226716067" duration="914000" />
  248 + <workItem from="1543226716067" duration="1107000" />
255 249 </task>
256 250 <servers />
257 251 </component>
258 252 <component name="TimeTrackingManager">
259   - <option name="totallyTimeSpent" value="30605000" />
  253 + <option name="totallyTimeSpent" value="30798000" />
260 254 </component>
261 255 <component name="ToolWindowManager">
262 256 <frame x="0" y="0" width="1440" height="900" extended-state="6" />
... ... @@ -375,8 +369,8 @@
375 369 </entry>
376 370 <entry file="file://$PROJECT_DIR$/api/routes/routes.js">
377 371 <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" />
  372 + <state relative-caret-position="229">
  373 + <caret line="284" column="25" lean-forward="true" selection-start-line="284" selection-start-column="25" selection-end-line="284" selection-end-column="25" />
380 374 <folding />
381 375 </state>
382 376 </provider>
... ...