@@ 474,6 474,13 @@ class AnkiBridge:
return self.collection().sched
+ def multi(self, actions):
+ response = []
+ for item in actions:
+ response.append(AnkiConnect.handler(ac, item))
+ return response
+
+
def media(self):
collection = self.collection()
if collection is not None:
@@ 502,11 509,59 @@ class AnkiBridge:
return [field['name'] for field in model['flds']]
- def multi(self, actions):
- response = []
- for item in actions:
- response.append(AnkiConnect.handler(ac, item))
- return response
+ def confForDeck(self, deck):
+ if not deck in self.deckNames():
+ return False
+
+ id = self.collection().decks.id(deck)
+ return self.collection().decks.confForDid(id)
+
+
+ def saveConf(self, conf):
+ id = str(conf['id'])
+ if not id in self.collection().decks.dconf:
+ return False
+
+ mod = anki.utils.intTime()
+ usn = self.collection().usn()
+
+ conf['mod'] = mod
+ conf['usn'] = usn
+
+ self.collection().decks.dconf[id] = conf
+ self.collection().decks.changed = True
+ return True
+
+
+ def changeConf(self, decks, confId):
+ for deck in decks:
+ if not deck in self.deckNames():
+ return False
+
+ if not str(confId) in self.collection().decks.dconf:
+ return False
+
+ for deck in decks:
+ did = str(self.collection().decks.id(deck))
+ aqt.mw.col.decks.decks[did]['conf'] = confId
+
+ return True
+
+
+ def addConf(self, name, cloneFrom=1):
+ if not str(cloneFrom) in self.collection().decks.dconf:
+ return False
+
+ cloneFrom = self.collection().decks.getConf(cloneFrom)
+ return self.collection().decks.confId(name, cloneFrom)
+
+
+ def remConf(self, id):
+ if id == 1 or not str(id) in self.collection().decks.dconf:
+ return False
+
+ self.collection().decks.remConf(id)
+ return True
def deckNames(self):
@@ 760,6 815,11 @@ class AnkiConnect:
@webApi
+ def multi(self, actions):
+ return self.anki.multi(actions)
+
+
+ @webApi
def deckNames(self):
return self.anki.deckNames()
@@ 780,8 840,28 @@ class AnkiConnect:
@webApi
- def multi(self, actions):
- return self.anki.multi(actions)
+ def confForDeck(self, deck):
+ return self.anki.confForDeck(deck)
+
+
+ @webApi
+ def saveConf(self, conf):
+ return self.anki.saveConf(conf)
+
+
+ @webApi
+ def changeConf(self, decks, confId):
+ return self.anki.changeConf(decks, confId)
+
+
+ @webApi
+ def addConf(self, name, cloneFrom=1):
+ return self.anki.addConf(name, cloneFrom)
+
+
+ @webApi
+ def remConf(self, id):
+ return self.anki.remConf(id)
@webApi
@@ 103,6 103,35 @@ Below is a list of currently supported actions. Requests with invalid actions or
```
4
```
+
+* **multi**
+
+ Performs multiple actions in one request, returning an array with the response of each action (in the given order).
+
+ *Sample request*:
+ ```
+ {
+ "action": "multi",
+ "params": {
+ "actions": [
+ {"action": "deckNames"},
+ {
+ "action": "browse",
+ "params": {"query": "deck:current"}
+ }
+ ]
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ [
+ ["Default"],
+ [1494723142483, 1494703460437, 1494703479525]
+ ]
+ ```
+
* **deckNames**
Gets the complete list of deck names for the current user.
@@ 180,32 209,141 @@ Below is a list of currently supported actions. Requests with invalid actions or
]
```
-* **multi**
+* **confForDeck**
- Performs multiple actions in one request, returning an array with the response of each action (in the given order).
+ Gets the config group object for the given deck.
*Sample request*:
```
{
- "action": "multi",
+ "action": "confForDeck",
"params": {
- "actions": [
- {"action": "deckNames"},
- {
- "action": "browse",
- "params": {"query": "deck:current"}
- }
- ]
+ "deck": "Default"
}
}
```
*Sample response*:
```
- [
- ["Default"],
- [1494723142483, 1494703460437, 1494703479525]
- ]
+ {
+ "lapse": {
+ "leechFails": 8,
+ "delays": [10],
+ "minInt": 1,
+ "leechAction": 0,
+ "mult": 0
+ },
+ "dyn": false,
+ "autoplay": true,
+ "mod": 1502970872,
+ "id": 1,
+ "maxTaken": 60,
+ "new": {
+ "bury": true,
+ "order": 1,
+ "initialFactor": 2500,
+ "perDay": 20,
+ "delays": [1, 10],
+ "separate": true,
+ "ints": [1, 4, 7]
+ },
+ "name": "Default",
+ "rev": {
+ "bury": true,
+ "ivlFct": 1,
+ "ease4": 1.3,
+ "maxIvl": 36500,
+ "perDay": 100,
+ "minSpace": 1,
+ "fuzz": 0.05
+ },
+ "timer": 0,
+ "replayq": true,
+ "usn": -1
+ }
+ ```
+
+* **saveConf**
+
+ Saves the given config group, returning `true` on success or `false` if the ID of the config group is invalid (i.e.
+ it does not exist).
+
+ *Sample request*:
+ ```
+ {
+ "action": "saveConf",
+ "params": {
+ "conf": (config group object)
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ true
+ ```
+
+* **changeConf**
+
+ Changes the configuration group for the given decks to the one with the given ID. Returns `true` on success or
+ `false` if the given configuration group or any of the given decks do not exist.
+
+ *Sample request*:
+ ```
+ {
+ "action": "changeConf",
+ "params": {
+ "decks": ["Default"],
+ "confId": 1
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ true
+ ```
+
+* **addConf**
+
+ Creates a new config group with the given name, cloning from the group with the given ID, or from the default group
+ if this is unspecified. Returns the ID of the new config group, or `false` if the specified group to clone from does
+ not exist.
+
+ *Sample request*:
+ ```
+ {
+ "action": "addConf",
+ "params": {
+ "name": "Copy of Default",
+ "cloneFrom": 1
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ 1502972374573
+ ```
+
+* **remConf**
+
+ Removes the config group with the given ID, returning `true` if successful, or `false` if attempting to remove
+ either the default config group (ID = 1) or a config group that does not exist.
+
+ *Sample request*:
+ ```
+ {
+ "action": "remConf",
+ "params": {
+ "id": 1502972374573
+ }
+ }
+ ```
+
+ *Sample response*:
+ ```
+ true
```
* **addNote**