2016-07-16 05:29:42 +08:00
|
|
|
import ko from 'ko';
|
2014-09-02 08:15:31 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
import { SettingsGet } from 'Common/Globals';
|
2022-02-28 17:38:47 +08:00
|
|
|
import { defaultOptionsAfterRender } from 'Common/Utils';
|
2022-03-01 17:18:12 +08:00
|
|
|
import { addObservablesTo } from 'External/ko';
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-15 01:40:56 +08:00
|
|
|
import Remote from 'Remote/Admin/Fetch';
|
2021-02-19 19:09:20 +08:00
|
|
|
import { decorateKoCommands } from 'Knoin/Knoin';
|
2022-02-28 17:38:47 +08:00
|
|
|
import { AbstractViewSettings } from 'Knoin/AbstractViews';
|
2015-03-28 06:06:56 +08:00
|
|
|
|
2022-03-08 07:51:32 +08:00
|
|
|
export class AdminSettingsContacts extends AbstractViewSettings {
|
2016-07-16 05:29:42 +08:00
|
|
|
constructor() {
|
2022-02-28 17:38:47 +08:00
|
|
|
super();
|
2020-10-15 01:16:37 +08:00
|
|
|
this.defaultOptionsAfterRender = defaultOptionsAfterRender;
|
2020-10-27 18:09:24 +08:00
|
|
|
|
2023-02-21 18:52:50 +08:00
|
|
|
this.addSetting('contactsPdoDsn');
|
|
|
|
this.addSetting('contactsPdoUser');
|
|
|
|
this.addSetting('contactsPdoPassword');
|
|
|
|
this.addSetting('contactsPdoType', () => {
|
2022-02-28 17:38:47 +08:00
|
|
|
this.testContactsSuccess(false);
|
|
|
|
this.testContactsError(false);
|
|
|
|
this.testContactsErrorMessage('');
|
|
|
|
});
|
|
|
|
|
2023-02-21 17:22:59 +08:00
|
|
|
this.addSettings(['contactsEnable','contactsSync']);
|
2020-10-27 18:09:24 +08:00
|
|
|
|
2023-04-24 17:19:07 +08:00
|
|
|
this.addSetting('contactsMySQLSSLCA');
|
|
|
|
this.addSetting('contactsMySQLSSLVerify');
|
|
|
|
this.addSetting('contactsMySQLSSLCiphers');
|
|
|
|
|
2022-03-01 17:18:12 +08:00
|
|
|
addObservablesTo(this, {
|
2020-10-27 18:09:24 +08:00
|
|
|
testing: false,
|
|
|
|
testContactsSuccess: false,
|
|
|
|
testContactsError: false,
|
|
|
|
testContactsErrorMessage: ''
|
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2023-02-21 18:52:50 +08:00
|
|
|
this.addSetting('contactsSuggestionsLimit');
|
2023-01-17 18:52:07 +08:00
|
|
|
|
2021-03-10 18:44:48 +08:00
|
|
|
const supportedTypes = SettingsGet('supportedPdoDrivers') || [],
|
2020-09-24 15:58:35 +08:00
|
|
|
types = [{
|
|
|
|
id:'sqlite',
|
|
|
|
name:'SQLite'
|
|
|
|
},{
|
|
|
|
id:'mysql',
|
|
|
|
name:'MySQL'
|
|
|
|
},{
|
|
|
|
id:'pgsql',
|
|
|
|
name:'PostgreSQL'
|
|
|
|
}].filter(type => supportedTypes.includes(type.id));
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-24 15:58:35 +08:00
|
|
|
this.contactsSupported = 0 < types.length;
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2020-09-24 15:58:35 +08:00
|
|
|
this.contactsTypesOptions = types;
|
2016-07-16 05:29:42 +08:00
|
|
|
|
2019-07-05 03:19:24 +08:00
|
|
|
this.mainContactsType = ko
|
|
|
|
.computed({
|
2022-02-28 17:38:47 +08:00
|
|
|
read: this.contactsPdoType,
|
2021-03-16 18:38:40 +08:00
|
|
|
write: value => {
|
2022-02-28 17:38:47 +08:00
|
|
|
if (value !== this.contactsPdoType()) {
|
2020-07-20 20:33:33 +08:00
|
|
|
if (supportedTypes.includes(value)) {
|
2022-02-28 17:38:47 +08:00
|
|
|
this.contactsPdoType(value);
|
2020-09-24 15:58:35 +08:00
|
|
|
} else if (types.length) {
|
2022-02-28 17:38:47 +08:00
|
|
|
this.contactsPdoType('');
|
2019-07-05 03:19:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2022-02-28 17:38:47 +08:00
|
|
|
this.contactsPdoType.valueHasMutated();
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
}
|
2019-07-05 03:19:24 +08:00
|
|
|
})
|
|
|
|
.extend({ notify: 'always' });
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2021-02-19 19:09:20 +08:00
|
|
|
decorateKoCommands(this, {
|
2022-02-28 17:38:47 +08:00
|
|
|
testContactsCommand: self => self.contactsPdoDsn() && self.contactsPdoUser()
|
2021-02-19 19:09:20 +08:00
|
|
|
});
|
2016-07-16 05:29:42 +08:00
|
|
|
}
|
2014-08-21 23:08:34 +08:00
|
|
|
|
2016-09-10 06:38:16 +08:00
|
|
|
testContactsCommand() {
|
|
|
|
this.testContactsSuccess(false);
|
|
|
|
this.testContactsError(false);
|
|
|
|
this.testContactsErrorMessage('');
|
|
|
|
this.testing(true);
|
|
|
|
|
2021-12-03 07:11:19 +08:00
|
|
|
Remote.request('AdminContactsTest',
|
|
|
|
(iError, data) => {
|
|
|
|
this.testContactsSuccess(false);
|
|
|
|
this.testContactsError(false);
|
|
|
|
this.testContactsErrorMessage('');
|
|
|
|
|
|
|
|
if (!iError && data.Result.Result) {
|
|
|
|
this.testContactsSuccess(true);
|
2021-04-23 03:56:01 +08:00
|
|
|
} else {
|
2021-12-03 07:11:19 +08:00
|
|
|
this.testContactsError(true);
|
2022-10-10 19:52:56 +08:00
|
|
|
this.testContactsErrorMessage(data?.Result?.Message || '');
|
2021-04-23 03:56:01 +08:00
|
|
|
}
|
|
|
|
|
2021-12-03 07:11:19 +08:00
|
|
|
this.testing(false);
|
|
|
|
}, {
|
2023-04-24 17:19:07 +08:00
|
|
|
PdoType: this.contactsPdoType(),
|
|
|
|
PdoDsn: this.contactsPdoDsn(),
|
|
|
|
PdoUser: this.contactsPdoUser(),
|
|
|
|
PdoPassword: this.contactsPdoPassword(),
|
|
|
|
MySQLSSLCA: this.contactsMySQLSSLCA(),
|
|
|
|
MySQLSSLVerify: this.contactsMySQLSSLVerify(),
|
|
|
|
MySQLSSLCiphers: this.contactsMySQLSSLCiphers()
|
2021-12-03 07:11:19 +08:00
|
|
|
}
|
|
|
|
);
|
2016-09-10 06:38:16 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 05:29:42 +08:00
|
|
|
onShow() {
|
|
|
|
this.testContactsSuccess(false);
|
|
|
|
this.testContactsError(false);
|
|
|
|
this.testContactsErrorMessage('');
|
|
|
|
}
|
|
|
|
}
|