Browse Source

get my curriculum front end

dmr1725 4 years ago
parent
commit
a431ecf849

+ 4
- 2
client/App.js View File

@@ -11,6 +11,7 @@ import HomeScreen from './Screens/HomeScreen'
11 11
 import NotificationsScreen from './Screens/NotificationScreen'
12 12
 import SettingScreen from './Screens/SettingScreen'
13 13
 import AddTakenCourse from './Screens/AddTakenCourse'
14
+import MyCurriculum from './Screens/MyCurriculum'
14 15
 
15 16
 const Drawer = createDrawerNavigator()
16 17
 
@@ -32,7 +33,7 @@ export default function App() {
32 33
 
33 34
         try {
34 35
           // login user in backend
35
-          let response = await fetch('http://145636c98edd.ngrok.io/rest-auth/google/', {
36
+          let response = await fetch('http://8ad793de242b.ngrok.io/rest-auth/google/', {
36 37
             method: 'POST',
37 38
             headers: {
38 39
               'content-type': 'application/json'
@@ -53,7 +54,7 @@ export default function App() {
53 54
           const token = await SecureStore.getItemAsync('token')
54 55
 
55 56
           // storing our id
56
-          let id = await fetch('http://145636c98edd.ngrok.io/api/get_user_id', {
57
+          let id = await fetch('http://8ad793de242b.ngrok.io/api/get_user_id', {
57 58
             method: 'GET',
58 59
             headers: {
59 60
               'content-type': 'application/json',
@@ -98,6 +99,7 @@ export default function App() {
98 99
           <Drawer.Screen name="Notifications" component={NotificationsScreen} />
99 100
           <Drawer.Screen name="Settings" component={SettingScreen} />
100 101
           <Drawer.Screen name="Add Taken Courses" component={AddTakenCourse} />
102
+          <Drawer.Screen name="My Curriculum" component={MyCurriculum} />
101 103
         </Drawer.Navigator>
102 104
     </NavigationContainer>
103 105
   )

+ 2
- 2
client/Screens/AddTakenCourse.js View File

@@ -51,7 +51,7 @@ const AddTakenCourse = () => {
51 51
 
52 52
       let response = await axios({
53 53
         method: 'POST',
54
-        url: 'http://145636c98edd.ngrok.io/api/add_taken_course',
54
+        url: 'http://8ad793de242b.ngrok.io/api/add_taken_course',
55 55
         headers: {
56 56
           'content-type': 'application/json',
57 57
           Authorization: `Token ${token}`
@@ -85,7 +85,7 @@ const AddTakenCourse = () => {
85 85
       const token = await SecureStore.getItemAsync('token')
86 86
       const response = await axios({
87 87
           method: 'GET',
88
-          url: `http://145636c98edd.ngrok.io/api/find_course?code=${text}`,
88
+          url: `http://8ad793de242b.ngrok.io/api/find_course?code=${text}`,
89 89
           headers: {
90 90
             'content-type': 'application/json',
91 91
             Authorization: `Token ${token}`

+ 1
- 1
client/Screens/HomeScreen.js View File

@@ -11,7 +11,7 @@ function HomeScreen({ navigation }) {
11 11
     console.log(token, id)
12 12
 
13 13
     let response = await Axios({
14
-      url: 'http://145636c98edd.ngrok.io/api/hello',
14
+      url: 'http://8ad793de242b.ngrok.io/api/hello',
15 15
       method: 'GET',
16 16
       headers: {
17 17
           Authorization: `Token ${token}`

+ 107
- 0
client/Screens/MyCurriculum.js View File

@@ -0,0 +1,107 @@
1
+import React, {useState, useEffect} from 'react';
2
+import { View, StyleSheet, Text } from 'react-native';
3
+import axios from 'axios'
4
+import { Table, Row, Rows, TableWrapper, Col } from 'react-native-table-component';
5
+import {Picker} from '@react-native-community/picker'
6
+import * as SecureStore from 'expo-secure-store';
7
+
8
+
9
+const MyCurriculum = () =>{
10
+    const [year, setYear] = useState(2)
11
+    const [semester, setSemester] = useState(1)
12
+    const [tableHead, setTableHead] = useState(['','Code', 'Title', 'Credits', 'Grade'])
13
+    const [tableData, setTableData] = useState([])
14
+    const [tableTitle, setTableTitle] = useState([])
15
+
16
+    const getMyCurriculum = async()=>{
17
+        const token = await SecureStore.getItemAsync('token')
18
+        let id = await SecureStore.getItemAsync('id')
19
+        let user_id = parseInt(id)
20
+        let courses = []
21
+        let numbers = []
22
+
23
+        try {
24
+            let response = await axios(`http://8ad793de242b.ngrok.io/api/get_all_courses_by_semester?user_id=${user_id}&year=${year}&semestre=${semester}`, {
25
+                method: 'GET',
26
+                headers: {
27
+                    'content-type': 'application/json',
28
+                    Authorization: `Token ${token}`
29
+                },
30
+            })
31
+            response = response.data.list // javaScript object
32
+
33
+            // setting a column with numbers
34
+            for (let i = 1; i < response.length + 1; i++){
35
+                numbers.push(i)
36
+            }
37
+            setTableTitle(numbers)
38
+            
39
+            // convert javascript array of objects to a javascript 2d array
40
+            response.map((data)=>{
41
+                let info = [data.code, data.name, data.creditos, data.grade]
42
+                courses.push(info)
43
+
44
+            })
45
+            setTableData(courses)
46
+           } catch(error){
47
+               console.log(error)
48
+           }
49
+    }
50
+
51
+    useEffect(()=>{
52
+        console.log('dimelo')
53
+        getMyCurriculum()
54
+    }, [year, semester])
55
+
56
+
57
+    return (
58
+        <View style={styles.container}>
59
+            <Table borderStyle={{borderWidth: 2, borderColor: '#0f0f0f'}}>
60
+                <Row data={tableHead} flexArr={[0.9, 3.5, 10, 2.3, 2.3]} style={styles.head} textStyle={styles.text}/>
61
+                <TableWrapper style={styles.wrapper}>
62
+                    <Col data ={tableTitle} style={styles.title} heightArr={[28,28]} textStyle={styles.text}/>
63
+                    <Rows data={tableData} flexArr={[3.5,10,2.3,2.3]} style={styles.row} textStyle={styles.text} />
64
+
65
+                </TableWrapper>
66
+            </Table>
67
+            <View style={{flexDirection: 'row'}}>
68
+                <View style={{margin: 8}}>
69
+                    <Text>Year</Text>
70
+                    <Picker
71
+                            selectedValue={year}
72
+                            style={{ width: 50}}
73
+                            onValueChange={(itemValue, itemIndex) => setYear(itemValue) }>
74
+                            <Picker.Item label="1" value="1" />
75
+                            <Picker.Item label="2" value="2" />
76
+                            <Picker.Item label="3" value="3" />
77
+                            <Picker.Item label="4" value="4" />
78
+                            <Picker.Item label="5" value="5" />
79
+                            <Picker.Item label="6" value="6" />
80
+                    </Picker>
81
+                </View>
82
+                <View style={{margin: 8}}>
83
+                    <Text>Semester</Text>
84
+                    <Picker
85
+                            selectedValue={semester}
86
+                            style={{ width: 50}}
87
+                            onValueChange={(itemValue, itemIndex) => setSemester(itemValue) }>
88
+                            <Picker.Item label="1" value="1" />
89
+                            <Picker.Item label="2" value="2" />
90
+                            <Picker.Item label="3" value="3" />
91
+                    </Picker>
92
+                </View>
93
+            </View>
94
+        </View>
95
+    );
96
+}
97
+
98
+export default MyCurriculum
99
+
100
+const styles = StyleSheet.create({
101
+    container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
102
+    head: {  height: 40,  backgroundColor: '#e82020'  },
103
+    wrapper: { flexDirection: 'row' },
104
+    title: { flex: 1, backgroundColor: '#e82020' },
105
+    row: {  height: 28  },
106
+    text: { textAlign: 'center', fontSize:10 }
107
+  });

+ 2
- 2
client/Screens/SettingScreen.js View File

@@ -15,7 +15,7 @@ export default function SettingScreen() {
15 15
         let user_id = parseInt(id)
16 16
 
17 17
        try {
18
-        let response = await axios(`http://145636c98edd.ngrok.io/api/get_faculty_name?id=${user_id}`, {
18
+        let response = await axios(`http://8ad793de242b.ngrok.io/api/get_faculty_name?id=${user_id}`, {
19 19
             method: 'GET',
20 20
             headers: {
21 21
                 'content-type': 'application/json',
@@ -43,7 +43,7 @@ export default function SettingScreen() {
43 43
         try {
44 44
             let response = await axios({
45 45
                 method: 'PATCH',
46
-                url: 'http://145636c98edd.ngrok.io/api/update_faculty',
46
+                url: 'http://8ad793de242b.ngrok.io/api/update_faculty',
47 47
                 headers: {
48 48
                     Authorization: `Token ${token}`
49 49
                 },

+ 5
- 0
client/package-lock.json View File

@@ -6643,6 +6643,11 @@
6643 6643
       "resolved": "https://registry.npmjs.org/react-native-status-bar-height/-/react-native-status-bar-height-2.6.0.tgz",
6644 6644
       "integrity": "sha512-z3SGLF0mHT+OlJDq7B7h/jXPjWcdBT3V14Le5L2PjntjjWM3+EJzq2BcXDwV+v67KFNJic5pgA26cCmseYek6w=="
6645 6645
     },
6646
+    "react-native-table-component": {
6647
+      "version": "1.2.1",
6648
+      "resolved": "https://registry.npmjs.org/react-native-table-component/-/react-native-table-component-1.2.1.tgz",
6649
+      "integrity": "sha512-sapwO0bONfQtpWg3GVMwP5D3lGEJlxPB3c7fb0soXBynvCa+SBktacVZ9OmYJnIbRJ3uW5pS4tzNc8GmE+UScw=="
6650
+    },
6646 6651
     "react-native-web": {
6647 6652
       "version": "0.13.18",
6648 6653
       "resolved": "https://registry.npmjs.org/react-native-web/-/react-native-web-0.13.18.tgz",

+ 1
- 0
client/package.json View File

@@ -27,6 +27,7 @@
27 27
     "react-native-reanimated": "~1.13.0",
28 28
     "react-native-safe-area-context": "3.1.4",
29 29
     "react-native-screens": "~2.10.1",
30
+    "react-native-table-component": "^1.2.1",
30 31
     "react-native-web": "~0.13.12"
31 32
   },
32 33
   "devDependencies": {

BIN
server/CompanionApp/__pycache__/views.cpython-38.pyc View File