<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400"></a></p>

<p align="center">
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>

**About This Project -- 雲端管理服務**
===
> 最後修訂日： 2024/8/16

 2024/8/16 起平台正式更名為［雲端管理服務］

# 職安平台 (IR 見下方)

## 操作
### 一般使用者
1. **首頁**: 登入帳號密碼的地方。
2. **dashboard**: 登入成功後引導到的頁面。
3. **基線清查**: 該公司基本資料的存放處，包含員工資料、化學品資料、機械資料。
4. (中略)
5. **紅外線檢測**: 連接至 IR 網站；跟職安平台內的所有資訊毫無關係，但同寫在一個專案內。
6. **帳號管理**: 從畫面右上角，Hover 至使用者名稱後出現的列表中進入。

### 管理員

1. **首頁**: 登入帳號密碼的地方。
2. **dashboard**: 登入成功後引導到的頁面。
3. **教學指引管理**: 一般使用者在每個畫面的右下角有個操作指引鈕，裡面的圖片由此處更新。
4. **帳號管理**: 從畫面右上角，Hover 至使用者名稱後出現的列表中進入。

## 使用工具

- **PHP** -- use <u>composer</u> for package management
- **NPM** -- frontend package managing tool
- **Vue**
- **Vue-router**
- **Vuex**
- **SASS** embedded in Vue SFC
- **webpack** -- laravel mix
- **PostgreSQL**
- **Unit Test** for PHP code
- **Jquery** 漸漸沒在用了。舊的程式碼大多都用 Jquery 寫；新的改用 Vue
- **Bootstrap**

## Install Steps (可能有漏...)

- git clone
- npm ci
- composer install
- update `.env`
  - You need to change database account/pwd, which should be the same as the setting in your computer. 
  - You can change any value in this file.
- create new database, which named as: `isha`.
- `php artisan migrate` (可能部分文件要手動修正一下...) & import DB data
  - 2023.03.13 update: Instead use `migration`, you can also use `psql` command. (recommand)
  - If you use `psql`, both schema and data will be imported.
  1. Download the backup data from our dataserver, which might be named as isha_backup.sql.
  2. Open terminal in your OS.
  3. Enter `psql -U <your-psql-username> isha < isha_backup.sql`
- php artisan optimize:clear

## Directory Structure

```
└─── app
  └──── Exports
  └──── Imports
  └──── Http
     └──── Controllers
  └──── Models
  └──── Repositories
  └──── Services
  └──── Supports        
```

- **Exports**: 輸出 excel 或 word 文件的 Class
- **Imports**: 匯入 excel 或 word 文件的 Class
- **Controllers**: 根據 MVC 架構，按理說這裡要放所有業務邏輯，但這樣很難 debug，所以邏輯改放在 Services，然後 Controllers 會呼叫 Services。
- **Models**: 管理資料庫欄位及設定各 table relationships 的地方，這裡面通常沒有太多業務邏輯。
- **Repositories**: 透過 Eloquent Query 獲取 DB 內資料的地方。
- **Services**: Controllers 跟 Repositories 之間互溝通的橋樑。從 Controller 獲得 user inputs，再把 inputs 傳給 repositories 跟 DB 互動。
- 主要是看[這個網站](https://laravel5-book.kejyun.com/structure/service-repository-structure-principle/)上的守則在維護架構。

## 部署位置

<p>
目前共部署在 3 個機台上，一個為<strong>測試機台</strong>；另兩個為正式機台。正式機台又分為大眾使用的<strong>正式版</strong>，以及為做推廣用途、以教學為目的的<strong>教育版</strong>。
</p>

<p>
機台的詳細資訊 (主機位置、設定、測試用帳密等) 還請再聯繫負責人獲取。
</p>

## Git Branches

<p>
目前主要更新在三個 branches 上，其他都不太動。default main branch 非 Master branch 請注意。
</p>

1. **Authed** => 部署至 教育版 的分支。缺少 IR 及部分功能 (提醒功能、部分改以 Vue 重構的程式碼)。
2. **Authed-v2** => 部署至 正式版 的分支。缺少 IR 功能 (客戶要求)。
3. **merge-thermal-and-main** => 部署至 測試版 的分支。具完整功能。

<p>
目前以第三個分支作為 develop branch。(因為目前分太多有點混亂，所以就不再獨立一個 develop branch)
</p>

最新版分支區分如下： (雲端管理與IR已正式合併)
1. **merge-thermal-and-main** =>正式版與教育版
2. **merge-test-main** =>測試機

理論上正式版/教育版為一致版本，僅資料不同，教育版供協會展覽教學模擬測試使用。
一般需求更新一律先至測試機確認後在更新至正式版/教育版，除bug會同步pick撿檔案合併。

## How to Contribute

1. 先決定好你要新增的功能要部署在哪個機台，根據你的選擇先移動到該分支 (這邊以 Authed 分支舉例)
    ```
    git checkout <branch-name>
    ```

2. 在該分支下開新的分支，分支命名請簡述你要新增的功能是什麼 (例如：f/crud-articles-api 之類的)
    ```
    git checkout -b <new-branch-name>
    ```
3. 開始寫你的 code ...
4. 寫完上傳你的 code
5. 我會 merge 你的 code (這個 Git server 好像沒有 PR 的功能?? 只能手動)

<p>
如果是多個分支都會用到的功能，通常是先從 Authed-v2 分支出去，然後用 cherry-pick 合併。
</p>

## What you need to ask for before developing

1. .env
2. DB data for developing
3. deployment data

## 其他

- 目前有點 SPA + SSR 混用，程式碼還在重構中...
- 教育版帳號可透過 command 建立
- 信件透過 smtp 傳遞

✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂　

    我是分隔線 (∩´∀｀)∩

✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂✂

# IR

## 操作

### 一般使用者

1. **登入頁**: 登入帳號密碼的地方。目前 IR 跟職安平台已經連動帳號，我不知道這頁面還該不該留，總之留著。
2. **dashboard**: 登入成功後引導到的頁面，一個寫著「歡迎來到紅外線檢測網站」的首頁。不論是從登入頁登入還是從職安平台導入都會來這。
3. **單位**: 該公司基本資料的存放處，包含區域、廠區、單位、及箱體資訊。
4. **巡檢計畫**: 訂定巡檢計畫詳細內容、巡檢計畫時程的地方。
      - 巡檢計畫就是一份稽查單，巡檢人員須在約定時間內填寫並上傳稽查單的結果。
5. **查核**: 巡檢人員依據計畫做了查訪後上傳的紀錄，我們稱為巡檢單。此處為巡檢單放置處。巡檢單需要由管理層級人員審核，因此此處被稱為查核區。
6. **系統管理**: 這裡會列出子帳號以及職務的一覽表。同時可在此設定子帳號的職務，職務會影響到子帳號對網站內容的修改權。

### 管理員

1. **首頁**: 登入帳號密碼的地方。
2. **dashboard**: 登入成功後引導到的頁面，同樣也寫著「歡迎來到紅外線檢測網站」，但跟一般使用者的首頁屬於不同網址。左側欄顯示廠商一覽表跟風險等級評估。
3. **風險等級評估**: 巡檢單的結果會被評為「正常」或是「異常」，其依據為風險等級評估裡的資料。風險評估等級的設定可在此處做更改。
    - <span style="color: #e22">注意！！此功能僅供管理員使用，一般使用者無法使用此功能。</span>
4. **廠商一覽**：此處顯示所有參與紅外線檢測的廠商。目前預設是廠商創建職安平台帳號時，同時會創建 IR 帳號，但之後此功能應該會修正。可在此頁點擊進入任一廠商，進入後可像廠商進入他們的頁面一樣管理他們的資料。除此之外，管理員才有對查核進行審核的功能。
    - <span style="color: #e22">注意！！此功能僅供管理員使用，一般使用者無法使用此功能。</span>

## 使用工具
- 見上方職安平台的「使用工具」列表

## Directory Structure

```
└─── app
  └──── Checkers
  └──── Classes
  └──── Exports
  └──── Imports
  └──── Http
     └──── Controllers
  └──── Models
  └──── Repositories
  └──── Services
  └──── Supports
└─── resources
  └──── js
     └──── middleware.js
     └──── router.js
     └──── store.js
```

- **Checkers**: 檢查使用者輸入是否符合所需條件，例如帳號密碼為必填等。
  - 其實針對每個 Request 都應該要實作 checker，但實在太忙了後來都沒做。
- **Classes**: 自定義 custom classes。你可以在此隨時增加你所需的 Class。
- **middleware.js**: Vue-router Navigation Guard functions.  Read [this official document](https://v3.router.vuejs.org/guide/advanced/navigation-guards.html) to learn more detail.
- **store.js**: Vuex variables and mutation functions.
- (剩下內容皆與職安平台相同)

## Git Branches

目前主要更新在 `merge-thermal-and-main` 這個分支上，此分支同時為開發分支及部署分支。  
其他分支為 feature branches，**若非您所負責的 feature，請不要擅自改動它**。  

## Before you commit...

1. If you revise any `.vue` file, you need to run compile and bundle your `.vue` first.  
2. So don't forget to run the command below before git committing.
    ```
    npm run prod
    ```
3. Don't forget to remove `Log::info()` or `console.log()` before you commit.
4. That's all!  HAPPY CODING!

## How to Contribute

### General Usecase
1. First, you need to know which feature you should comtribute, then switch to that feature branch.
    ```
    git checkout <feature-branch-name>
    ```
2. For some case, if you want to append a new feature; while which of this branch hasn't existed yet.  Then you need to create new branch first.
    - The branch's name should be named as: `f/<feature-description>`, like `f/add-article-CRUD`, which means that the feature is to add Articles CRUD API.
    ```
    git checkout -b <new-feature-branch-name>
    ```
3. Coding time...
4. Commit your changes and push your commits.
5. <span style="color: #e22">IMPORTANT！DON'T TRY TO MERGE YOUR BRANCH TO ANY OTHER BRANCH!</span>
   - Since BONOBO GIT Server doesn't support PR feature, so I'll do the merge work for you instead.


### Complicated Usecase
If you add a feature, which needed to be applied to both <u>isha website</u> as well as <u>IR website</u>, then you should use `cherry-pick` to combine your commits.
```
/* if you have a feature new to merge Authed and IR branch */

git checkout -b f/something-new-feature
git commit
git merge Authed
git cherry-pick <commit-hash-value>
```

## 其他
- 目前有使用任務佇列 + 背景執行使用forver套件管理work -aiReg