Skip to content

Commit

Permalink
chang other notifycation to start&pause&resume
Browse files Browse the repository at this point in the history
  • Loading branch information
郑子辉 committed Jan 12, 2024
1 parent 269e472 commit 98ca2e5
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 6 deletions.
17 changes: 17 additions & 0 deletions backend/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,28 @@ class Meta:
'notify_on_filament_change',
'notify_on_other_print_events',
'notify_on_heater_status',
'notify_on_print_start',
'notify_on_print_pause',
'notify_on_print_resume',
)

read_only_fields = (
'id', 'user', 'created_at', 'updated_at',
)

def create(self, validated_data):
if validated_data.get('notify_on_other_print_events'):
validated_data['notify_on_print_start'] = True
validated_data['notify_on_print_pause'] = True
validated_data['notify_on_print_resume'] = True
return super().create(validated_data)

def update(self, instance, validated_data):
if validated_data.get('notify_on_other_print_events'):
validated_data['notify_on_print_start'] = True
validated_data['notify_on_print_pause'] = True
validated_data['notify_on_print_resume'] = True
return super().update(instance, validated_data)

def validate_name(self, name):
name = name.strip()
Expand Down
3 changes: 2 additions & 1 deletion backend/app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class PrinterAdmin(admin.ModelAdmin):
class NotificationSettingAdmin(admin.ModelAdmin):
list_select_related = True
list_display = ('get_user', 'name', 'enabled', 'notify_on_failure_alert', 'notify_on_print_done',
'notify_on_print_cancelled', 'notify_on_filament_change', 'notify_on_other_print_events', 'notify_on_heater_status')
'notify_on_print_cancelled', 'notify_on_filament_change', 'notify_on_other_print_events', 'notify_on_heater_status',
'notify_on_print_start','notify_on_print_pause','notify_on_print_resume',)
search_fields = ('user__email',)
readonly_fields = ['user', ]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

# Generated by Django 4.0.10 on 2024-01-07 07:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('app', '0074_auto_20231009_2220'),
]

operations = [
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_pause',
field=models.BooleanField(blank=True, default=False),
),
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_resume',
field=models.BooleanField(blank=True, default=False),
),
migrations.AddField(
model_name='notificationsetting',
name='notify_on_print_start',
field=models.BooleanField(blank=True, default=False),
),
]
4 changes: 4 additions & 0 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,10 @@ class NotificationSetting(models.Model):

notify_on_heater_status = models.BooleanField(blank=True, default=False)

notify_on_print_start = models.BooleanField(blank=True, default=False)
notify_on_print_pause = models.BooleanField(blank=True, default=False)
notify_on_print_resume = models.BooleanField(blank=True, default=False)

created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

Expand Down
3 changes: 3 additions & 0 deletions backend/app/views/web_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def unsubscribe_email(request):
nsetting.notify_on_filament_change = False
nsetting.notify_on_other_print_events = False
nsetting.notify_on_heater_status = False
nsetting.notify_on_print_start = False
nsetting.notify_on_print_pause = False
nsetting.notify_on_print_resume = False
nsetting.save()
elif email_list == 'account_notification':
user.account_notification_by_email = False
Expand Down
10 changes: 8 additions & 2 deletions backend/notifications/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ def feature_for_notification_type(self, notification_type: str) -> Optional[Feat
if notification_type in (notification_types.HeaterCooledDown, notification_types.HeaterTargetReached):
return Feature.notify_on_heater_status

if notification_type in list(notification_types.OTHER_PRINT_EVENT_MAP.values()):
return Feature.notify_on_other_print_events
if notification_type == notification_types.PrintStarted:
return Feature.notify_on_print_start

if notification_type == notification_types.PrintResumed:
return Feature.notify_on_print_resume

if notification_type == notification_types.PrintPaused:
return Feature.notify_on_print_pause

return None

def should_plugin_handle_notification_type(
Expand Down
6 changes: 6 additions & 0 deletions backend/notifications/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Feature(enum.Enum):
notify_on_filament_change = 'notify_on_filament_change'
notify_on_other_print_events = 'notify_on_other_print_events'
notify_on_heater_status = 'notify_on_heater_status'
notify_on_print_start = 'notify_on_print_start',
notify_on_print_pause = 'notify_on_print_pause',
notify_on_print_resume = 'notify_on_print_resume',


@dataclasses.dataclass(frozen=True)
Expand Down Expand Up @@ -99,6 +102,9 @@ def supported_features(self) -> Set[Feature]:
Feature.notify_on_filament_change,
Feature.notify_on_other_print_events,
Feature.notify_on_heater_status,
Feature.notify_on_print_start,
Feature.notify_on_print_pause,
Feature.notify_on_print_resume,
}

def env_vars(self) -> Dict:
Expand Down
18 changes: 15 additions & 3 deletions frontend/src/config/user-preferences/notification-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ export default [
enabledByDefault: true,
},
{
id: 'notify_on_other_print_events',
title: 'When other event happens',
description: 'Such as start, pause, and resume',
id: 'notify_on_print_start',
title: 'When start event happens',
description: 'start',
enabledByDefault: false,
},
{
id: 'notify_on_print_pause',
title: 'When pause event happens',
description: 'pause',
enabledByDefault: false,
},
{
id: 'notify_on_print_resume',
title: 'When resume event happens',
description: 'resume',
enabledByDefault: false,
},
],
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/notifications/plugins/TwilioPlugin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ export default {
notify_on_filament_change: 'f',
notify_on_other_print_events: 'f',
notify_on_heater_status: 'f',
notify_on_print_start: 'f',
notify_on_print_paus: 'f',
notify_on_print_resume: 'f'
},
})
}, 1000)
Expand Down
5 changes: 5 additions & 0 deletions website/docs/developer-guides/plugins/notification-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ This method is optional if your plugin doesn't support **any** of the following
- notify_on_other_print_events
- notify_on_heater_status

- notify_on_print_start
- notify_on_print_pause
- notify_on_print_resume

notify_on_other_print_events move to (notify_on_print_start /notify_on_print_pause /notify_on_print_resume)

##### Signature {#signature-4}

Expand Down

0 comments on commit 98ca2e5

Please sign in to comment.