Skip to content

Commit

Permalink
Merge pull request #76 from moevm/app-is-ready-fix
Browse files Browse the repository at this point in the history
Statistic Page
  • Loading branch information
LeraChernyakova authored Dec 18, 2024
2 parents faca75a + fd96d55 commit 563440d
Show file tree
Hide file tree
Showing 20 changed files with 711 additions and 336 deletions.
Binary file modified .gitignore
Binary file not shown.
64 changes: 57 additions & 7 deletions client/src/components/pages/StatisticPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
type="date"
:max="new Date().toISOString().split('T')[0]"
@change="updateDateLimits()"
required
/>
</div>
<div style="display: flex; flex-direction: column">
Expand All @@ -43,10 +44,27 @@
min=""
max=""
disabled
required
/>
</div>
</div>
</div>
<div v-if="statType === 'plants'">
<div class="inputs-labels">Типы растений</div>
<div class="scrollable-checkboxes">
<label v-for="type in types" :key="type" class="checkbox-labels">
<input v-model="selectedTypes" type="checkbox" :value="type" :disabled="statType !== 'plants'" />
{{ type }}
<br>
</label>
</div>
<div class="inputs-labels">Условия освещения</div>
<label class="checkbox-labels"><input v-model="lighting" type="checkbox" value="Тенелюбивые" :disabled="statType !== 'plants'"/> Тенелюбивые</label>
<br>
<label class="checkbox-labels"><input v-model="lighting" type="checkbox" value="Полутеневые" :disabled="statType !== 'plants'"/> Полутеневые</label>
<br>
<label class="checkbox-labels"><input v-model="lighting" type="checkbox" value="Светолюбивые" :disabled="statType !== 'plants'"/> Светолюбивые</label>
</div>
<button style="margin-top: 2%" class="green-button-white-text" @click="getStatistic">Отобразить</button>
<div class="inputs-labels">
Работа с базой данных
Expand Down Expand Up @@ -94,7 +112,10 @@ export default {
statType: '',
dateFrom: '',
dateTo: '',
lighting: [],
chart: false,
types: [],
selectedTypes: [],
data: {
labels: [],
datasets: []
Expand Down Expand Up @@ -158,6 +179,16 @@ export default {
};
},
created() {
axios
.get(`/api/plants/types/typesArray`)
.then((response) => {
response.data.types.forEach(elem => {
this.types.push(elem);
});
})
},
methods: {
updateDateLimits() {
const today = new Date().toISOString().split("T")[0];
Expand All @@ -183,17 +214,28 @@ export default {
},
getStatistic() {
this.chart = false
const datePeriod = {
filter: {
timeFrom: this.formatTimeFrom(this.dateFrom),
timeTo: this.formatTimeTo(this.dateTo)
this.chart = false;
let filter = {};
if (this.statType === "plants") {
filter = {
filter: {
timeFrom: this.formatTimeFrom(this.dateFrom),
timeTo: this.formatTimeTo(this.dateTo),
},
type: this.selectedTypes,
lightCondition: this.lighting
}
} else {
filter = {
filter: {
timeFrom: this.formatTimeFrom(this.dateFrom),
timeTo: this.formatTimeTo(this.dateTo)
}
}
}
this.data = { datasets: [], labels: [] };
axios
.post(`/api/stats/${this.statType}`, datePeriod)
.post(`/api/stats/${this.statType}`, filter)
.then((response) => {
if (this.statType === 'plants') {
if (Object.keys(response.data).length === 0) {
Expand Down Expand Up @@ -448,4 +490,12 @@ export default {
padding: 10px;
background-color: #FFFFFF;
}
.scrollable-checkboxes {
max-height: 120px;
overflow-y: auto;
border: 1px solid #ccc;
padding: 10px;
border-radius: 4px;
}
</style>
13 changes: 13 additions & 0 deletions server/api/plants/v1/plants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ service PlantsAPI {
get: "/api/plants/archive/{userId}"
};
};
rpc ListPlantTypesV1(GetPlantTypesV1Request) returns (GetPlantTypesV1Response) {
option (google.api.http) = {
get: "/api/plants/types/typesArray"
};
};
}

message Filter {
Expand Down Expand Up @@ -285,4 +290,12 @@ message GetArchivedPlantsV1Request{
}
message GetArchivedPlantsV1Response{
repeated Plant plants = 1;
}

message GetPlantTypesV1Request {

}

message GetPlantTypesV1Response {
repeated string types = 1;
}
2 changes: 2 additions & 0 deletions server/api/stats/v1/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ service StatsAPI {

message GetPlantsStatsV1Request{
TimeFilter filter = 1;
repeated string type = 2;
repeated string lightCondition = 3;
}
message GetPlantsStatsV1Response{
message StatsInfo {
Expand Down
22 changes: 22 additions & 0 deletions server/internal/handlers/plants/list_plant_types_v1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package plants

import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

api "plants/internal/pkg/pb/plants/v1"
)

func (h *Handler) ListPlantTypesV1(
ctx context.Context,
req *api.GetPlantTypesV1Request,
) (*api.GetPlantTypesV1Response, error) {
types, err := h.storage.GetTypes(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "some error occured while getting types %v", err)
}
return &api.GetPlantTypesV1Response{
Types: types,
}, nil
}
1 change: 1 addition & 0 deletions server/internal/handlers/plants/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Storage interface {
AddTradeToUser(ctx context.Context, userId, tradeId primitive.ObjectID) error
GetPlantsByUserId(ctx context.Context, userId string, isSold bool) ([]*models.Plant, error)
AddPlantToUser(ctx context.Context, plant *models.Plant) error
GetTypes(ctx context.Context) ([]string, error)
}

type Handler struct {
Expand Down
6 changes: 6 additions & 0 deletions server/internal/handlers/stats/get_plants_stats_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ func (h *Handler) GetPlantsStatsV1(ctx context.Context,
req *api.GetPlantsStatsV1Request,
) (*api.GetPlantsStatsV1Response, error) {
fltr := parseFilter(req.Filter)
if len(req.LightCondition) != 0 {
fltr["light_condition"] = req.LightCondition
}
if len(req.Type) != 0 {
fltr["type"] = req.Type
}
plants, err := h.storage.GetPlantsStats(ctx, fltr)
if err != nil {
return nil, status.Errorf(codes.Internal, "Error occured %v", err)
Expand Down
4 changes: 2 additions & 2 deletions server/internal/pkg/pb/data/v1/data.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/internal/pkg/pb/data/v1/data_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 563440d

Please sign in to comment.