This commit is contained in:
2021-07-02 00:50:21 +02:00
parent a4202dfabe
commit de421fb3d5
3 changed files with 107 additions and 26 deletions
+11 -1
View File
@@ -11,7 +11,7 @@
class="search-exit" class="search-exit"
:src="exitIcon" :src="exitIcon"
alt="exit-icon" alt="exit-icon"
@click="() => (compSearchedValue = '')" @click="clearValue"
/> />
</div> </div>
</template> </template>
@@ -23,6 +23,7 @@ export default defineComponent({
data: () => ({ data: () => ({
exitIcon: require("@/assets/icon-exit.svg"), exitIcon: require("@/assets/icon-exit.svg"),
}), }),
emits: ["update:searchedValue", "clearValue"],
props: { props: {
searchedValue: { searchedValue: {
type: String, type: String,
@@ -36,6 +37,9 @@ export default defineComponent({
type: String, type: String,
required: true, required: true,
}, },
clearValue: {
type: Function,
},
}, },
setup(props, { emit }) { setup(props, { emit }) {
@@ -50,6 +54,11 @@ export default defineComponent({
); );
} }
const clearValue = () => {
compSearchedValue.value = "";
emit("clearValue");
};
const updateValue = (e) => { const updateValue = (e) => {
if (!props.updateOnInput && e.keyCode == 13) if (!props.updateOnInput && e.keyCode == 13)
emit("update:searchedValue", compSearchedValue.value); emit("update:searchedValue", compSearchedValue.value);
@@ -58,6 +67,7 @@ export default defineComponent({
return { return {
compSearchedValue, compSearchedValue,
updateValue, updateValue,
clearValue,
}; };
}, },
}); });
+16
View File
@@ -0,0 +1,16 @@
import { defineComponent } from 'vue';
export default defineComponent({
methods: {
localeDate(dateString: string) {
return new Date(dateString).toLocaleDateString("pl-PL", {
weekday: "long",
day: "numeric",
month: "2-digit",
year: "numeric",
hour:"2-digit",
minute: "2-digit"
})
}
}
})
+80 -25
View File
@@ -2,18 +2,31 @@
<section class="history-view"> <section class="history-view">
<h2>Historia rozkładów jazdy</h2> <h2>Historia rozkładów jazdy</h2>
<div style="display: flex; justify-content: center; align-items: center"> <div
style="
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
"
>
<search-box <search-box
v-model:searchedValue="searchDriver" v-model:searchedValue="searchedDriver"
titleToTranslate="history.search-driver" titleToTranslate="history.search-driver"
:updateOnInput="false" @clearValue="clearDriver"
@keypress="keyPressed"
></search-box> ></search-box>
<search-box <search-box
v-model:searchedValue="searchTrain" v-model:searchedValue="searchedTrain"
titleToTranslate="history.search-train" titleToTranslate="history.search-train"
:updateOnInput="false" @clearValue="clearTrain"
@keypress="keyPressed"
></search-box> ></search-box>
<action-button @click="search" style="margin-left: 0.5em">
Szukaj
</action-button>
</div> </div>
<div class="history_list"> <div class="history_list">
@@ -27,8 +40,9 @@
!item.terminated ? navigateToTrain(item.trainNo) : null !item.terminated ? navigateToTrain(item.trainNo) : null
" "
style="cursor: pointer" style="cursor: pointer"
>{{ item.trainCategoryCode }} {{ item.trainNo }}</span
> >
{{ item.trainCategoryCode }} {{ item.trainNo }}
</span>
<div> <div>
<b>{{ item.route.replace("|", " - ") }}</b> <b>{{ item.route.replace("|", " - ") }}</b>
@@ -62,12 +76,17 @@
</div> </div>
<div> <div>
<b>Rozpoczęcie:</b> <b>Stacje:</b>
{{ new Date(item.beginDate).toLocaleString() }} {{ item.confirmedStopsCount }} /
{{ item.allStopsCount }}
</div> </div>
<div> <div>
<b>Zakończenie:</b> {{ new Date(item.endDate).toLocaleString() }} <b>Rozpoczęcie:</b>
{{ localeDate(item.beginDate) }}
</div> </div>
<div><b>Zakończenie:</b> {{ localeDate(item.endDate) }}</div>
</div> </div>
</li> </li>
</ul> </ul>
@@ -76,12 +95,15 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import SearchBox from "@/components/Global/SearchBox.vue"; import { defineComponent, Ref, ref } from "vue";
import axios from "axios"; import axios from "axios";
import { computed, defineComponent, Ref, ref } from "vue";
import ActionButton from "@/components/Global/ActionButton.vue";
import SearchBox from "@/components/Global/SearchBox.vue";
import dateMixin from "@/mixins/dateMixin";
const API_URL = const API_URL =
"https://stacjownik-api-m9z4k.ondigitalocean.app/api/getTimetables?count=15"; "https://stacjownik-api-m9z4k.ondigitalocean.app/api/getTimetables";
interface APIResponse { interface APIResponse {
errorMessage: string | null; errorMessage: string | null;
@@ -112,34 +134,44 @@ interface TimetableHistory {
fulfilled: boolean; fulfilled: boolean;
} }
async function fetchData(): Promise<TimetableHistory[] | null> { async function fetchData(props: {
searchedDriver?: string;
searchedTrain?: string;
maxCount?: number;
}): Promise<TimetableHistory[] | null> {
const queries: string[] = [];
if (!props.searchedDriver && !props.searchedTrain) queries.push("count=15");
if (props.maxCount) queries.push(`count=${props.maxCount}`);
if (props.searchedDriver) queries.push(`driver=${props.searchedDriver}`);
if (props.searchedTrain) queries.push(`train=${props.searchedTrain}`);
const responseData: APIResponse | null = await ( const responseData: APIResponse | null = await (
await axios.get(API_URL) await axios.get(`${API_URL}?${queries.join("&")}`)
).data; ).data;
return responseData?.response || null; return responseData?.response || null;
} }
export default defineComponent({ export default defineComponent({
components: { SearchBox }, components: { SearchBox, ActionButton },
mixins: [dateMixin],
setup() { setup() {
// const historyList = computed(async () => await fetchData());
const historyList: Ref<TimetableHistory[] | null> = ref([]); const historyList: Ref<TimetableHistory[] | null> = ref([]);
const searchDriver = ref(""); const searchedDriver = ref("");
const searchTrain = ref(""); const searchedTrain = ref("");
const maxCount = ref(15);
(async () => { (async () => {
const response = await fetchData(); const response = await fetchData({});
historyList.value = response; historyList.value = response;
console.log(response);
})(); })();
return { return {
historyList, historyList,
searchDriver, searchedDriver,
searchTrain, searchedTrain,
maxCount,
}; };
}, },
methods: { methods: {
@@ -149,6 +181,29 @@ export default defineComponent({
params: { queryTrain: trainNo.toString() }, params: { queryTrain: trainNo.toString() },
}); });
}, },
clearDriver() {
this.searchedDriver = "";
this.search();
},
clearTrain() {
this.searchedTrain = "";
this.search();
},
async search() {
this.historyList = await fetchData({
searchedDriver: this.searchedDriver,
searchedTrain: this.searchedTrain,
});
},
keyPressed({ keyCode }) {
if (keyCode == 13) this.search();
},
}, },
}); });
</script> </script>
@@ -199,7 +254,7 @@ h3 {
} }
ul { ul {
width: 800px; width: 1000px;
} }
li { li {