Skip to content

Commit

Permalink
Merge branch 'main' into prod/festapp
Browse files Browse the repository at this point in the history
  • Loading branch information
miakh committed Nov 13, 2024
2 parents 2da8cd6 + 921dab6 commit 3b6798a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
1 change: 1 addition & 0 deletions lib/dataModels/Tb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class InformationTb{
class InformationHidden{
const InformationHidden();
String get table => "information_hidden";
String get occasion => "occasion";
String get id => "id";
String get data => "data";
String get data_correct => "correct";
Expand Down
10 changes: 8 additions & 2 deletions lib/dataServices/DbInformation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,22 @@ class DbInformation {

static Future<void> updateInformation(InformationModel info) async {
if(info.type == InformationModel.gameType){


Map<String, dynamic> upsertObj = {
Tb.information_hidden.data: info.informationHidden?.data,
Tb.information_hidden.occasion: RightsService.currentOccasion!
};
Map<String, dynamic> ref;
if(info.informationHidden?.id != null){
upsertObj.addAll({
Tb.information_hidden.id: info.informationHidden?.id
Tb.information_hidden.id: info.informationHidden?.id,
});
ref = await _supabase.from(Tb.information_hidden.table).update(upsertObj).eq(Tb.information_hidden.id, info.informationHidden!.id!).select(Tb.information_hidden.id).single();
} else {
ref = await _supabase.from(Tb.information_hidden.table).insert(upsertObj).select(Tb.information_hidden.id).single();
}

var ref = await _supabase.from(Tb.information_hidden.table).upsert(upsertObj).select(Tb.information_hidden.id).single();
info.informationHidden = InformationHiddenModel(id: ref[Tb.information_hidden.id]);
}
var upsertObj = {
Expand Down
47 changes: 20 additions & 27 deletions lib/pages/AdministrationOccasion/GameTab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:fstapp/pages/AdministrationOccasion/GameCheckPointsContent.dart';
import 'package:fstapp/pages/AdministrationOccasion/GameSettingsContent.dart';
import 'package:fstapp/pages/AdministrationOccasion/GameUserGroupsContent.dart';
import 'package:fstapp/themeConfig.dart';

class GameTab extends StatefulWidget {
const GameTab({Key? key}) : super(key: key);
Expand Down Expand Up @@ -33,39 +34,16 @@ class _GameTabState extends State<GameTab> with SingleTickerProviderStateMixin {
child: Column(
children: [
Container(
color: ThemeConfig.backgroundColor(context),
height: 40,
alignment: Alignment.centerLeft,
child: TabBar(
controller: _tabController,
isScrollable: true,
tabs: [
Row(
children: [
Icon(Icons.gamepad),
Padding(
padding: const EdgeInsets.all(12),
child: Text("Check points".tr()),
),
],
),
Row(
children: [
Icon(Icons.groups),
Padding(
padding: const EdgeInsets.all(12),
child: Text("Groups".tr()),
),
],
),
Row(
children: [
Icon(Icons.settings),
Padding(
padding: const EdgeInsets.all(12),
child: Text("Settings".tr()),
),
],
),
buildTab(Icons.gamepad, "Check points".tr()),
buildTab(Icons.groups, "Groups".tr()),
buildTab(Icons.settings, "Settings".tr()),
],
),
),
Expand All @@ -84,6 +62,21 @@ class _GameTabState extends State<GameTab> with SingleTickerProviderStateMixin {
),
);
}

Widget buildTab(IconData icon, String text) {
return Row(
children: [
Icon(icon, color: ThemeConfig.blackColor(context)),
Padding(
padding: const EdgeInsets.all(12),
child: Text(
text,
style: TextStyle(color: ThemeConfig.blackColor(context)),
),
),
],
);
}
}


Expand Down
24 changes: 14 additions & 10 deletions scripts/database/functions/game_update_settings.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
CREATE OR REPLACE FUNCTION game_update_settings(
oc BIGINT,
start_time TIMESTAMPTZ,
end_time TIMESTAMPTZ
new_start_time TIMESTAMPTZ,
new_end_time TIMESTAMPTZ
)
RETURNS JSONB
LANGUAGE plpgsql
AS $$
DECLARE
existing_data JSONB;
updated_game_data JSONB;
BEGIN
-- Check if the user is an editor on the occasion
IF (SELECT get_is_editor_on_occasion(oc)) <> TRUE THEN
Expand All @@ -17,15 +18,18 @@ BEGIN
-- Retrieve existing data JSON if any
SELECT data INTO existing_data FROM public.occasions WHERE id = oc;

-- Update the data JSON with new game settings for start and end times
-- Create or update the "game" object with new start and end times, preserving other keys in "game"
updated_game_data := COALESCE(existing_data->'game', '{}'::jsonb) || jsonb_build_object(
'start', CASE WHEN new_start_time IS NOT NULL THEN to_jsonb(new_start_time) ELSE 'null'::jsonb END,
'end', CASE WHEN new_end_time IS NOT NULL THEN to_jsonb(new_end_time) ELSE 'null'::jsonb END
);

-- Update the data JSON with the updated "game" data
UPDATE public.occasions
SET data = jsonb_set(
COALESCE(data, '{}'::jsonb), -- Ensure data is an empty JSON if NULL
ARRAY['game'], -- Path to the "game" key
jsonb_build_object( -- New game settings JSON object
'start', to_jsonb(start_time),
'end', to_jsonb(end_time)
),
COALESCE(data, '{}'::jsonb), -- Ensure data is an empty JSON if NULL
ARRAY['game'], -- Path to the "game" key
updated_game_data, -- Updated game data with merged start and end times
true
)
WHERE id = oc;
Expand All @@ -36,4 +40,4 @@ BEGIN
'message', 'Game settings updated successfully'
);
END;
$$;
$$;

0 comments on commit 3b6798a

Please sign in to comment.