From 760bb0fe2e1370fe7318cb19323f510157af05b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Da=CC=88hne?= <janis.daehne@informatik.uni-halle.de>
Date: Tue, 1 Nov 2022 15:29:17 +0100
Subject: [PATCH] - added programming lanauge to open/closed exercise overviews

---
 .../closedExercisesSite/listView.tsx          | 32 ++++++++++++++++++-
 .../openExercises/listView.tsx                | 32 ++++++++++++++++++-
 .../closedExercisesSiteActions.ts             |  4 +++
 .../openExercisesSiteActions.ts               |  5 +++
 4 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/src/components/sites/allAccessibleExercisesSite/closedExercisesSite/listView.tsx b/src/components/sites/allAccessibleExercisesSite/closedExercisesSite/listView.tsx
index 5abfe339..3697bc0e 100644
--- a/src/components/sites/allAccessibleExercisesSite/closedExercisesSite/listView.tsx
+++ b/src/components/sites/allAccessibleExercisesSite/closedExercisesSite/listView.tsx
@@ -52,7 +52,8 @@ const mapStateToProps = (rootState: RootState, props: MyProps) => {
     //test0: rootState...
     //test: props.test
     ...props,
-    langId: rootState.i18nState.langId
+    langId: rootState.i18nState.langId,
+    pLangs: rootState.pLangsState.pLangs,
   }
 }
 
@@ -209,6 +210,24 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
                   }
                 </span>
               </Table.HeaderCell>
+              <Table.HeaderCell>
+                <span className="clickable"
+                      onClick={() => {
+                        this.props.setSortByKey('lastUpdatedAt',
+                          rotateSorting<ExercisePreviewFromBackend>(this.props.sortDirection,
+                            this.props.sortByKey,
+                            'lastUpdatedAt',
+                          ),
+                          this.props.displayAsViaCode
+                        )
+                      }}
+                >
+                  {
+                    <HelpPopup icon="puzzle piece"
+                               defaultText={getI18n(this.props.langId,'Programming language')}/>
+                  }
+                </span>
+              </Table.HeaderCell>
               {
                 this.props.displayAsViaCode &&
                 <Table.HeaderCell>
@@ -239,6 +258,9 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
           <Table.Body>
             {
               list.map((exercisePreview, index) => {
+
+                let programmingLanguageForRelease = this.props.pLangs.find(p => p.id === exercisePreview.releasedForPLangId)
+
                 //we can't use the id for the key because one exercise can have multiple releases...
                 return (
                   <Table.Row key={exercisePreview.generatedCode}>
@@ -318,6 +340,14 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
                         />
                       }
                     </Table.Cell>
+                    <Table.Cell>
+                      {
+                        programmingLanguageForRelease &&
+                        <span>
+                          { programmingLanguageForRelease.displayName }
+                        </span>
+                      }
+                    </Table.Cell>
                     {
                       this.props.displayAsViaCode &&
                       <Table.Cell>
diff --git a/src/components/sites/allAccessibleExercisesSite/openExercises/listView.tsx b/src/components/sites/allAccessibleExercisesSite/openExercises/listView.tsx
index 81eb8640..3a02c37e 100644
--- a/src/components/sites/allAccessibleExercisesSite/openExercises/listView.tsx
+++ b/src/components/sites/allAccessibleExercisesSite/openExercises/listView.tsx
@@ -57,7 +57,8 @@ const mapStateToProps = (rootState: RootState, props: MyProps) => {
     //test0: rootState...
     //test: props.test
     ...props,
-    langId: rootState.i18nState.langId
+    langId: rootState.i18nState.langId,
+    pLangs: rootState.pLangsState.pLangs,
   }
 }
 
@@ -218,6 +219,24 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
                   }
                 </span>
               </Table.HeaderCell>
+              <Table.HeaderCell>
+                <span className="clickable"
+                      onClick={() => {
+                        this.props.setSortByKey('lastUpdatedAt',
+                          rotateSorting<ExercisePreviewFromBackend>(this.props.sortDirection,
+                            this.props.sortByKey,
+                            'lastUpdatedAt',
+                          ),
+                          this.props.displayAsViaCode
+                        )
+                      }}
+                >
+                  {
+                    <HelpPopup icon="puzzle piece"
+                               defaultText={getI18n(this.props.langId,'Programming language')}/>
+                  }
+                </span>
+              </Table.HeaderCell>
               {
                 this.props.displayAsViaCode &&
                 <Table.HeaderCell>
@@ -256,6 +275,9 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
           <Table.Body>
             {
               list.map((exercisePreview, index) => {
+
+                let programmingLanguageForRelease = this.props.pLangs.find(p => p.id === exercisePreview.releasedForPLangId)
+
                 //we can't use the id for the key because one exercise can have multiple releases...
                 return (
                   <Table.Row key={exercisePreview.generatedCode}>
@@ -341,6 +363,14 @@ class AllAccessibleExercisesList extends React.Component<Props, any> {
                         />
                       }
                     </Table.Cell>
+                    <Table.Cell>
+                      {
+                        programmingLanguageForRelease &&
+                        <span>
+                          { programmingLanguageForRelease.displayName }
+                        </span>
+                      }
+                    </Table.Cell>
                     {
                       this.props.displayAsViaCode &&
                       <Table.Cell>
diff --git a/src/state/actions/allAccessibleExercises/closedExercisesSite/closedExercisesSiteActions.ts b/src/state/actions/allAccessibleExercises/closedExercisesSite/closedExercisesSiteActions.ts
index f97833c8..60e6ef0e 100644
--- a/src/state/actions/allAccessibleExercises/closedExercisesSite/closedExercisesSiteActions.ts
+++ b/src/state/actions/allAccessibleExercises/closedExercisesSite/closedExercisesSiteActions.ts
@@ -25,6 +25,7 @@ import {PaginationPostDataWithTagsFilter} from '../../../../types/pagination'
 import {PaginationHelper} from '../../../../helpers/paginationHelper'
 import {debounce} from 'lodash-es'
 import {searchInputDebounceInMs} from '../../../../constants'
+import {getPLangsAsync} from '../../plangSettingsView/pLangsCrudActions'
 
 export function loadClosedExerciseViaCodeAsync(): AwaitActions {
   return async (dispatch) => {
@@ -34,6 +35,8 @@ export function loadClosedExerciseViaCodeAsync(): AwaitActions {
     dispatch(resetTagsFilter())
     await dispatch(loadManageTagsSite())
 
+    await dispatch(getPLangsAsync())
+
     await dispatch(getClosedExercisesViaCode())
   }
 }
@@ -46,6 +49,7 @@ export function loadClosedExerciseViaVisibilityAsync(): AwaitActions {
     dispatch(resetTagsFilter())
     await dispatch(loadManageTagsSite())
 
+    await dispatch(getPLangsAsync())
 
     await dispatch(getClosedExercisesViaVisibility())
   }
diff --git a/src/state/actions/allAccessibleExercises/openExercisesSite/openExercisesSiteActions.ts b/src/state/actions/allAccessibleExercises/openExercisesSite/openExercisesSiteActions.ts
index 1f49a60e..561b4774 100644
--- a/src/state/actions/allAccessibleExercises/openExercisesSite/openExercisesSiteActions.ts
+++ b/src/state/actions/allAccessibleExercises/openExercisesSite/openExercisesSiteActions.ts
@@ -28,6 +28,7 @@ import {PaginationPostData, PaginationPostDataWithTagsFilter} from '../../../../
 import {PaginationHelper} from '../../../../helpers/paginationHelper'
 import {GET_openExercisesViaCodeAction} from '../../../reducers/allAccessibleExercises/openExercisesSite/getOpenExercisesViaCodeCrudReducer'
 import {GET_openExercisesViaVisibilityAction} from '../../../reducers/allAccessibleExercises/openExercisesSite/getOpenExercisesViaVisibilityCrudReducer'
+import {getPLangsAsync} from '../../plangSettingsView/pLangsCrudActions'
 
 
 export function setOpenExercisesViaCode(openExercisesViaCode: ReadonlyArray<ExercisePreviewsFrontendExclusive>): SET_openExercisesViaCodeAction {
@@ -53,6 +54,8 @@ export function loadOpenExercisePreviewsViaCodeAsync(): AwaitActions {
     dispatch(resetTagsFilter())
     await dispatch(loadManageTagsSite())
 
+    await dispatch(getPLangsAsync())
+
     await dispatch(getOpenExercisesViaCode())
   }
 }
@@ -65,6 +68,8 @@ export function loadOpenExercisePreviewsViaVisibilityAsync(): AwaitActions {
     dispatch(resetTagsFilter())
     await dispatch(loadManageTagsSite())
 
+    await dispatch(getPLangsAsync())
+
     await dispatch(getOpenExercisesViaVisibility())
   }
 }
-- 
GitLab