GWM : notification
This commit is contained in:
parent
fe522b5388
commit
9c92cd63e3
93
main.go
93
main.go
@ -383,23 +383,27 @@ func TranslateFilters(app *pocketbase.PocketBase, dataset string, filterGroups [
|
|||||||
sourceData = append(sourceData, source)
|
sourceData = append(sourceData, source)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a map for quick lookup of translations
|
|
||||||
translationMap := make(map[string]string)
|
|
||||||
for _, source := range sourceData {
|
|
||||||
var value string
|
|
||||||
switch langKey {
|
|
||||||
case "value_en":
|
|
||||||
value = source.ValueEn
|
|
||||||
case "value_ar":
|
|
||||||
value = source.ValueAr
|
|
||||||
default:
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
translationMap[source.Value] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
// Translate the filter data
|
// Translate the filter data
|
||||||
for i, filter := range filterGroups {
|
for i, filter := range filterGroups {
|
||||||
|
|
||||||
|
// Create a map for quick lookup of translations
|
||||||
|
translationMap := make(map[string]string)
|
||||||
|
for _, source := range sourceData {
|
||||||
|
var value string
|
||||||
|
switch langKey {
|
||||||
|
case "value_en":
|
||||||
|
value = source.ValueEn
|
||||||
|
case "value_ar":
|
||||||
|
value = source.ValueAr
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if source.Key == filter.FilterKey {
|
||||||
|
translationMap[source.Value] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if filter.FilterKey == "TIME_PERIOD" {
|
if filter.FilterKey == "TIME_PERIOD" {
|
||||||
// Skip translation for TIME_PERIOD
|
// Skip translation for TIME_PERIOD
|
||||||
continue
|
continue
|
||||||
@ -457,6 +461,7 @@ func main() {
|
|||||||
message_en := e.Record.GetString("message_en")
|
message_en := e.Record.GetString("message_en")
|
||||||
title_ar := e.Record.GetString("title_ar")
|
title_ar := e.Record.GetString("title_ar")
|
||||||
message_ar := e.Record.GetString("message_ar")
|
message_ar := e.Record.GetString("message_ar")
|
||||||
|
notificationID := e.Record.GetString("id") // Get the new notification ID
|
||||||
|
|
||||||
// Initialize Firebase
|
// Initialize Firebase
|
||||||
opt := option.WithCredentialsFile("firebase-adminsdk.json")
|
opt := option.WithCredentialsFile("firebase-adminsdk.json")
|
||||||
@ -513,6 +518,47 @@ func main() {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("✅ Successfully sent message: %s\n", response)
|
fmt.Printf("✅ Successfully sent message: %s\n", response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the pushed_notification field
|
||||||
|
var pushedNotifications []string
|
||||||
|
|
||||||
|
// Get existing pushed_notification JSON field
|
||||||
|
pushedNotificationsJSON := user.GetString("pushed_notification")
|
||||||
|
if pushedNotificationsJSON != "" {
|
||||||
|
err := json.Unmarshal([]byte(pushedNotificationsJSON), &pushedNotifications)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("⚠️ Error parsing pushed_notification for user %s: %v", user.GetString("id"), err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append the new notification ID if not already present
|
||||||
|
alreadyExists := false
|
||||||
|
for _, existingID := range pushedNotifications {
|
||||||
|
if existingID == notificationID {
|
||||||
|
alreadyExists = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !alreadyExists {
|
||||||
|
pushedNotifications = append(pushedNotifications, notificationID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert back to JSON
|
||||||
|
updatedPushedNotifications, err := json.Marshal(pushedNotifications)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("⚠️ Error marshalling pushed_notification JSON: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the user record in the database
|
||||||
|
user.Set("pushed_notification", string(updatedPushedNotifications))
|
||||||
|
if err := app.Dao().SaveRecord(user); err != nil {
|
||||||
|
log.Printf("❌ Error updating pushed_notification for user %s: %v", user.GetString("id"), err)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("✅ Updated pushed_notification for user %s\n", user.GetString("id"))
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,7 +823,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
cResRaw := utils.ProcessChartData(chartData, languageSourceConverted, langKey)
|
cResRaw := utils.TranslateChartData(chartData, languageSourceConverted, langKey)
|
||||||
|
|
||||||
//responce data structure
|
//responce data structure
|
||||||
chartHeadingKey := "chart_heading_" + language
|
chartHeadingKey := "chart_heading_" + language
|
||||||
@ -785,14 +831,13 @@ func main() {
|
|||||||
tabHeadingKey := "tab_heading_" + language
|
tabHeadingKey := "tab_heading_" + language
|
||||||
// Correct conditional assignment for "response"
|
// Correct conditional assignment for "response"
|
||||||
recordResult := map[string]interface{}{
|
recordResult := map[string]interface{}{
|
||||||
"url": apiURL,
|
"url": apiURL,
|
||||||
"dataset": record.GetString("dataset"),
|
"dataset": record.GetString("dataset"),
|
||||||
"main_id": record.GetString("main_id"),
|
"main_id": record.GetString("main_id"),
|
||||||
"sub_id": record.GetString("sub_id"),
|
"sub_id": record.GetString("sub_id"),
|
||||||
"kpi": record.GetString("kpi"),
|
"kpi": record.GetString("kpi"),
|
||||||
"is_chart": record.GetString("is_chart"),
|
"is_chart": record.GetString("is_chart"),
|
||||||
"chart_type": record.GetString("chart_type"),
|
"chart_type": record.GetString("chart_type"),
|
||||||
// "response": cResRaw,
|
|
||||||
"group_by": record.GetString("group_by"),
|
"group_by": record.GetString("group_by"),
|
||||||
"chart_heading": record.GetString(chartHeadingKey),
|
"chart_heading": record.GetString(chartHeadingKey),
|
||||||
"chart_sub_heading": record.GetString(chartSubHeadingKey),
|
"chart_sub_heading": record.GetString(chartSubHeadingKey),
|
||||||
|
|||||||
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
BIN
pb_data/data.db-shm
Normal file
BIN
pb_data/data.db-shm
Normal file
Binary file not shown.
0
pb_data/data.db-wal
Normal file
0
pb_data/data.db-wal
Normal file
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
BIN
pb_data/logs.db-shm
Normal file
BIN
pb_data/logs.db-shm
Normal file
Binary file not shown.
BIN
pb_data/logs.db-wal
Normal file
BIN
pb_data/logs.db-wal
Normal file
Binary file not shown.
@ -234,10 +234,10 @@ func difference(data []Observation) float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to add commas to a number string
|
// Function to add commas to a number string
|
||||||
func addCommas(num string) string {
|
func addCommas(num string, suffix string) string {
|
||||||
n := len(num)
|
n := len(num)
|
||||||
if n <= 3 {
|
if n <= 3 {
|
||||||
return num
|
return num + suffix // Attach suffix directly if no commas needed
|
||||||
}
|
}
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
start := n % 3
|
start := n % 3
|
||||||
@ -249,7 +249,7 @@ func addCommas(num string) string {
|
|||||||
for i := start; i < n; i += 3 {
|
for i := start; i < n; i += 3 {
|
||||||
sb.WriteString("," + num[i:i+3])
|
sb.WriteString("," + num[i:i+3])
|
||||||
}
|
}
|
||||||
return sb.String()
|
return sb.String() + suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatNumberWithCommas(value float64, suffix string) string {
|
func formatNumberWithCommas(value float64, suffix string) string {
|
||||||
@ -293,7 +293,7 @@ func applyConversion(value float64, conversion string, numberFormat string) stri
|
|||||||
formatNumber := func(v float64, suffix string) string {
|
formatNumber := func(v float64, suffix string) string {
|
||||||
if suffix == "" || suffix == "K" || suffix == "M" || suffix == "B" || suffix == "T" {
|
if suffix == "" || suffix == "K" || suffix == "M" || suffix == "B" || suffix == "T" {
|
||||||
if v == float64(int(v)) { // No decimal part
|
if v == float64(int(v)) { // No decimal part
|
||||||
return addCommas(strconv.Itoa(int(v)))
|
return addCommas(strconv.Itoa(int(v)), suffix)
|
||||||
}
|
}
|
||||||
return formatNumberWithCommas(v, suffix)
|
return formatNumberWithCommas(v, suffix)
|
||||||
}
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
// ProcessChartData processes chart data with language source data to produce the result based on the language key.
|
// TranslateChartData processes chart data with language source data to produce the result based on the language key.
|
||||||
func ProcessChartData(chartData []map[string]interface{}, languageSource []map[string]interface{}, langKey string) []map[string]interface{} {
|
func TranslateChartData(chartData []map[string]interface{}, languageSource []map[string]interface{}, langKey string) []map[string]interface{} {
|
||||||
// Helper function to find translation
|
// Helper function to find translation
|
||||||
findTranslation := func(key string, value string) string {
|
findTranslation := func(key string, value string) string {
|
||||||
for _, langEntry := range languageSource {
|
for _, langEntry := range languageSource {
|
||||||
Loading…
Reference in New Issue
Block a user