NotificationPreferences

TsgcHTMLComponent_NotificationPreferences: 카테고리마다 행이 하나, 채널(앱 내, 푸시, 이메일)마다 체크박스가 하나씩 있는 테이블로, Delphi, C++ Builder 및 .NET에서 사용할 수 있습니다. 값은 애플리케이션이 불러오고 저장합니다.

TsgcHTMLComponent_NotificationPreferences

라이브러리는 아무것도 저장하지 않습니다. OnLoadPreferences는 한 사용자의 값을 애플리케이션에 요청하고, OnSavePreferences는 사용자가 체크한 내용을 돌려주며, 이를 유지하는 것은 개발자의 몫입니다. 값은 name=value 쌍이며 1 또는 0을 갖고, 제공되는 모든 쌍은 항상 존재합니다. 모든 에디션에서 동작합니다.

컴포넌트 클래스

TsgcHTMLComponent_NotificationPreferences(유닛 sgcHTML_Component_NotificationPreferences)

렌더링

테이블: 카테고리마다 행 하나, 채널마다 체크박스 하나, 그리고 저장 버튼

언어

Delphi, C++ Builder, .NET

카테고리를 제공하고, 값을 불러오고 저장하기

사용자에게 알릴 수 있는 항목마다 Categories에 항목을 하나씩 추가하고, 자체 저장소에서 OnLoadPreferences에 응답하고, OnSavePreferences로 도착하는 내용을 유지하며, 게시된 폼은 세션에서 가져온 사용자와 함께 ProcessAction으로 라우팅합니다.

uses
  sgcHTML_Session, sgcHTML_Component_NotificationPreferences;

var
  oPrefs: TsgcHTMLComponent_NotificationPreferences;
begin
  oPrefs := TsgcHTMLComponent_NotificationPreferences.Create(nil);
  try
    oPrefs.PreferencesID := 'prefs';
    oPrefs.Title := 'How you want to hear about it';
    oPrefs.SaveCaption := 'Save preferences';

    with oPrefs.Categories.Add do
    begin
      Name := 'orders';
      Caption := 'A new order arrives';
    end;
    with oPrefs.Categories.Add do
    begin
      Name := 'billing';
      Caption := 'A payment fails';
    end;

    oPrefs.OnLoadPreferences := PrefsLoad;
    oPrefs.OnSavePreferences := PrefsSave;

    // the user comes from the session, never from the form
    oPrefs.LoadPreferences(sgcHTMLRequestSession.UserID);
    Response := oPrefs.HTML;   // one row per category, one checkbox per channel
  finally
    oPrefs.Free;
  end;
end;

// the application owns the values: one category.channel=1 or =0 per pair
procedure TMain.PrefsLoad(Sender: TObject; const aUserID: string;
  aValues: TStrings);
begin
  aValues.Add('orders.inapp=1');
  aValues.Add('orders.push=0');
  aValues.Add('orders.email=1');
end;

procedure TMain.PrefsSave(Sender: TObject; const aUserID: string;
  aValues: TStrings);
var
  i: Integer;
begin
  // every offered pair is here, with 1 or 0
  for i := 0 to aValues.Count - 1 do
    MyStore.Save(aUserID, aValues.Names[i], aValues.Values[aValues.Names[i]] = '1');
end;

// in the message handler that receives the form the table posts
if oPrefs.ProcessAction(vUser, vAction, vPostedFields) then
  oHTMX.PushFragment(vGuid, oPrefs.HTML);
// includes: sgcHTML_Session.hpp, sgcHTML_Component_NotificationPreferences.hpp

TsgcHTMLComponent_NotificationPreferences *oPrefs = new TsgcHTMLComponent_NotificationPreferences(NULL);
try
{
  oPrefs->PreferencesID = "prefs";
  oPrefs->Title = "How you want to hear about it";
  oPrefs->SaveCaption = "Save preferences";

  TsgcHTMLPreferenceCategory *orders = oPrefs->Categories->Add();
  orders->Name = "orders";
  orders->Caption = "A new order arrives";
  TsgcHTMLPreferenceCategory *billing = oPrefs->Categories->Add();
  billing->Name = "billing";
  billing->Caption = "A payment fails";

  oPrefs->OnLoadPreferences = PrefsLoad;
  oPrefs->OnSavePreferences = PrefsSave;

  // the user comes from the session, never from the form
  oPrefs->LoadPreferences(sgcHTMLRequestSession()->UserID);
  String html = oPrefs->HTML;   // one row per category, one checkbox per channel
}
__finally
{
  delete oPrefs;
}

// the application owns the values: one category.channel=1 or =0 per pair
void __fastcall TMain::PrefsLoad(TObject *Sender, const String aUserID,
  TStrings *aValues)
{
  aValues->Add("orders.inapp=1");
  aValues->Add("orders.push=0");
  aValues->Add("orders.email=1");
}

void __fastcall TMain::PrefsSave(TObject *Sender, const String aUserID,
  TStrings *aValues)
{
  // every offered pair is here, with 1 or 0
  for (int i = 0; i < aValues->Count; i++)
    MyStore->Save(aUserID, aValues->Names[i], aValues->Values[aValues->Names[i]] == "1");
}

// in the message handler that receives the form the table posts
if (oPrefs->ProcessAction(vUser, vAction, vPostedFields))
  oHTMX->PushFragment(vGuid, oPrefs->HTML);
using esegece.sgcWebSockets;

var prefs = new TsgcHTMLComponent_NotificationPreferences();
prefs.PreferencesID = "prefs";
prefs.Title = "How you want to hear about it";
prefs.SaveCaption = "Save preferences";

var orders = prefs.Categories.Add();
orders.Name = "orders";
orders.Caption = "A new order arrives";
var billing = prefs.Categories.Add();
billing.Name = "billing";
billing.Caption = "A payment fails";

prefs.OnLoadPreferences += PrefsLoad;
prefs.OnSavePreferences += PrefsSave;

// the user comes from the session, never from the form
string user = sgcHTMLSessionHelpers.sgcHTMLRequestSession()?.UserID ?? "";
prefs.LoadPreferences(user);
string html = prefs.HTML;   // one row per category, one checkbox per channel

// the application owns the values: one category.channel=1 or =0 per pair
void PrefsLoad(object sender, string userID, List<string> values)
{
    values.Add("orders.inapp=1");
    values.Add("orders.push=0");
    values.Add("orders.email=1");
}

void PrefsSave(object sender, string userID, List<string> values)
{
    // every offered pair is here, with 1 or 0
    foreach (var line in values)
    {
        int eq = line.IndexOf('=');
        myStore.Save(userID, line.Substring(0, eq), line.Substring(eq + 1) == "1");
    }
}

// in the message handler that receives the form the table posts
if (prefs.ProcessAction(user, action, postedFields))
    htmx.PushFragment(guid, prefs.HTML);

주요 속성 및 메서드

가장 자주 사용하게 되는 멤버.

카테고리

CategoriesTsgcHTMLPreferenceCategories 컬렉션이며, 각 TsgcHTMLPreferenceCategory는 값에서 그리고 체크박스의 이름으로 사용되는 고정된 키인 Name과, 사용자가 읽으며 렌더링될 때 이스케이프되는 Caption을 갖습니다. Caption이 비어 있으면 Name이 대신 사용되고, Name이 비어 있는 카테고리는 건너뜁니다. IndexOfName이 하나를 찾습니다.

채널

ChannelsncInApp, ncPush, ncEmail 중 어느 것이 열을 갖는지 선택하며, 기본값은 세 가지 모두입니다. 채널 이름은 TsgcHTMLComponent_Notification과 공유되며, 이 컴포넌트는 무언가를 전달하기 전에 OnGetChannel에서 애플리케이션에 그 이름을 묻습니다.

값은 제공되는 카테고리와 채널마다 하나씩 있는 name=value 쌍이며, 예를 들면 orders.inapp=1, orders.push=0, orders.email=1입니다. 키는 카테고리 Name, 점, 그리고 채널 키 inapp, push 또는 email입니다. 채널이 켜져 있으면 값은 1이고 꺼져 있으면 0입니다. ValueKey(aCategory, aChannel)이 키를 만듭니다.

로딩

LoadPreferences(aUserID)Values를 비우고 OnLoadPreferences(aUserID, aValues)를 발생시킵니다. 이때 aValues를 해당 사용자의 category.channel=1 줄로 채우십시오. Values는 렌더링된 내용, 또는 마지막으로 저장된 내용의 읽기 전용 뷰입니다. 생략한 쌍은 체크되지 않은 상태로 표시됩니다.

저장

OnSavePreferences(aUserID, aValues)는 제공되는 모든 쌍을 새 값과 함께 받으므로, 애플리케이션이 없는 키의 의미를 추측할 필요가 없습니다. SavePreferences(aUserID, aPosted)는 도착한 그대로의 폼을 받으며, 여기에는 체크된 상자만 들어 있습니다. ProcessAction(aUserID, aAction, aPosted)가 이를 라우팅하고, False를 반환하는 경우는 액션이 prefsSave가 아닐 때입니다.

위조된 폼

저장된 폼은 클라이언트가 보낸 데이터로 전달되므로 마크업에는 사용자 ID가 기록되지 않으며, 컴포넌트가 제공하지 않는 카테고리나 채널을 지정하는 항목은 모두 무시됩니다. 위조된 폼은 환경설정의 범위를 넓힐 수 없습니다. 컴포넌트는 권한 부여를 강제하지 않습니다. 액션을 수행하는 사용자는 폼이 아니라 요청 세션(sgcHTMLRequestSession)에서 가져오십시오.

체크박스 하나 읽기

IsChecked(aCategory, aChannel)는 쌍이 켜져 있는지 알려 주고, SetChecked(aCategory, aChannel, aValue)1 또는 0Values에 기록하며, IsOffered(aCategory, aChannel)는 카테고리가 존재하고 채널에 열이 있으면 True입니다.

모양과 액션

PreferencesID는 루트 요소의 ID이자 prefs 필드로 게시되는 값이므로, 테이블이 여러 개인 페이지도 어느 테이블이 응답했는지 알 수 있습니다. Title, SaveCaption, EmptyText가 텍스트를 설정하고, ShowSave(기본적으로 켜짐)는 버튼을 표시합니다. 폼은 prefsSavedata-sgc-ws-send 폼으로 게시하며, 체크된 상자마다 category.channel 필드가 하나씩 포함되며 그 값은 1입니다.

에디션

이 유닛은 SGC_HTML이 정의된 경우에 컴파일되며, sgcVer.inc는 Android와 iOS에는 이를 정의하지 않습니다. 모든 에디션에서 동작하며, sgcHTML은 sgcWebSockets와 별도로 판매되는 단독 팩입니다. 푸시 체크박스는 선택만 기록합니다. 푸시를 실제로 전달하려면 WebPush가 필요하며, 이는 Enterprise 및 All-Access 에디션에서만 사용할 수 있습니다.

관련 컴포넌트

알림 자체는 NotificationInbox가 표시하며, 사용자에게 페이지에서 알릴지 푸시로 알릴지는 Notification이 결정합니다.

계속 살펴보기

온라인 도움말이 찱포넌트의 전체 API 참조 및 사용 가이드입니다.
모든 sgcHTML 컴포넌트80개 이상의 컴포넌트 전체 기능 매트릭스를 둘러보십시오.
무료 체험판 다운로드30일 체험판은 60.HTML 데모 프로젝트를 포함하며, 그중 17.FieldService는 환경설정 테이블을 사용합니다.
가격전체 소스 코드가 포함된 Single, Team 및 Site 라이선스.
최고의 가성비: All-Access모든 eSeGeCe 제품과 프리미엄 지원이 포함되어 연 €1,059부터 이용할 수 있어요.
All-Access 가격 보기

시작할 준비가 되셨습니까?

무료 체험판을 다운로드하고 Delphi, C++ Builder 및 .NET에서 웹 UI를 구축하기 시작하십시오.