<p class="text-center">
<br><br>-CJJS-<br><Made by Team><br>
</p>
CJJS前端報告 05/14
===
# 預計本週目標
* - [ ] 確認共用變數名稱
* - [x] Github 協作模式
* - [x] Google-Forms-API完成接發表單
* - [x] 把使用者介面原型Demo
* - [ ] 互動介面的回傳參數
## :o: Google-Forms-API
>[name=Jerry]
參考連結 :link: https://developers.google.com/forms/api/quickstart/python
Google-forms-api初始化程式碼如下:
```python=
class GoogleAPIClient:
SECRET_PATH = './forms_json/client_secrets.json'
CREDS_PATH = './forms_json/token.json'
DISCOVERY_DOC="https://forms.googleapis.com/$discovery/rest?version=v1"
def __init__(self, serviceName: str, version: str, scopes: list) -> None:
#確認是否存在access token
if os.path.exists(self.CREDS_PATH):
self.creds = Credentials.from_authorized_user_file(self.CREDS_PATH, scopes)
# If there are no (valid) credentials available, let the user log in.
if not self.creds or not self.creds.valid:
if self.creds and self.creds.expired and self.creds.refresh_token:
self.creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
self.SECRET_PATH, scopes)
self.creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open(self.CREDS_PATH, 'w') as token:
token.write(self.creds.to_json())
self.googleAPIService = build(serviceName, version, credentials=self.creds)ㄈ
```
## :o: 創建表單
```python=
def create_form(self):
form=self.googleAPIService.forms().create(body=self.NEW_FORM).execute()
```
>透過建立物件(CLASS)來使用函式建立NEW_FORM表單
NEW_FORM形式如下:
``` python=
NEW_FORM = {
"info": {
"title": "Quickstart form",
}
}
```
---
## 問題格式
* 1.單選題
* 2.多選題
* 3.下拉式選單
* 4.簡答
* 5.詳答
### 單選題
>透過使用ADD_question函式來建立一個形式為NEW_QUESTION的單選題
``` python=
NEW_QUESTION = {
"requests": [{
"createItem": {
"item": {
"title": "In what year did the United States land a mission on the moon?",
"questionItem": {
"question": {
"required": True,
"choiceQuestion": {
"type": "RADIO",
"options": [
{"value": "1965"},
{"value": "1967"},
{"value": "1969"},
{"value": "1971"}
],
"shuffle": True
}
}
},
},
"location": {
"index": 2
}
}
}]
}
def Add_question(self,formid):
self.googleAPIService.forms().batchUpdate(formId=formid, body=self.NEW_QUESTION).execute()
```
### 多選題
>透過使用Add_Mul_que(表單ID,標題,要幾個選項,選項List)來建立多選題
``` python=
def Add_Mul_que(self,formid ,title,options,choice_text):
Mul_QUESTION = {
"requests": [{
"createItem": {
"item": {
"title": title,
"questionItem": {
"question": {
"required": True,
"choiceQuestion": {
"type": "CHECKBOX",
"options": [
self.generate_choice(options,choice_text)
],
"shuffle": True
}
}
}
},
"location": {
"index": self.get_form_info(formid)
}
}
}]
}
self.googleAPIService.forms().batchUpdate(formId=formid, body=Mul_QUESTION).execute()
```
### 下拉式選單
>透果使用ADD_DDM(表單ID,標題,選項,選項List) 來建立下拉式選單
``` python=
def ADD_DDM(self,formid,title,options,choice_text):
ADD_ddm= {
"requests": [{
"createItem": {
"item": {
"title": title,
"questionItem": {
"question": {
"required": True,
"choiceQuestion": {
"type": "DROP_DOWN",
"options": [
self.generate_choice(options,choice_text)
],
"shuffle": True
}
}
}
},
"location": {
"index":self.get_form_info(formid)
}
}
}]
}
self.googleAPIService.forms().batchUpdate(formId=formid, body=ADD_ddm).execute()
```
### 簡答
>簡答格式重點在"paragraph"==False
``` python=
def Short_reply(self, formid, title):
question = {
"requests": [{
"createItem": {
"item": {
"title": title,
"questionItem": {
"question": {
"required": True,
"textQuestion": {
"paragraph": False
}
}
}
},
"location": {
"index":self.get_form_info(formid)
}
}
}]
}
self.googleAPIService.forms().batchUpdate(formId=formid, body=question).execute()
```
### 詳答
>詳答格式重點在"paragraph"==True
``` python=
def Long_reply(self, formid, title):
question = {
"requests": [{
"createItem": {
"item": {
"title": title,
"questionItem": {
"question": {
"required": True,
"textQuestion": {
"paragraph": True
}
}
}
},
"location": {
"index":self.get_form_info(formid)
}
}
}]
}
self.googleAPIService.forms().batchUpdate(formId=formid, body=question).execute()
```
---
## :o: 取得回覆
>此舉可以取得表單所有回覆
``` python=
def get_reply(self,form_id):
result=self.googleAPIService.forms().responses().list(formId=form_id).execute()
return result
```
## :x:監控回覆
>這個需要付錢,所以打算以其他形式完成
---
## 小結論
**經過這週調研發現表單應該可以直接用正常方式created
再將它傳送給需要使用這份表單的人,我們只需要學會接收表單就好**
```graphviz
digraph graphname {
node [shape=rectangle]; // 设置节点形状为矩形
rankdir=TD; // 设置图的方向为从上到下
{rank=same; "已創建好的表單"; 使用者;}
"接收表單" [style=filled, fillcolor=red, fontcolor=black]; // 修改接收表單节点的样式
已創建好的表單 -> 使用者;
"接收表單" -> 已創建好的表單;
使用者 -> 已創建好的表單;
}
```
## 使用者介面的構想、製作與範例
**這周目標設定是做出給教授能夠使用的介面
首先
我們暫時規劃如下:**
###### 新用戶加入 > 初始化自動跳出初始化google表單(還未做出) > 確認身分 >
###### > 後端權限設定完成(還未做出) > 給予有(出作業、考試資訊的介面、學生回饋表)
**再來就是介面的部份:**


###### 以上都為進入課業區後跳出的對話框樣式,區別只是說明樣式顏色都能自訂製作。下方的作業、考試資訊、學生回饋都為按鈕,點入後會跳出google表單能夠填寫(連結表單尚未做出)。
透過點選選單或是自行輸入(查詢課業區等等...)都會將狀態改成課業狀態
並開始執行一系列關於課業的操做
# ****以上為使用者介面初步想法以及試做****
<p class="text-center">
<br><br>-CJJS-<br><Made by Team><br>
</p>